The Artima Developer Community
Sponsored Link

Java Buzz Forum
document.body vs. document.documentElement in IE

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Kevin Dangoor

Posts: 1101
Nickname: tazzzzz
Registered: Jul, 2003

Kevin Dangoor is a developer with JSTOR
document.body vs. document.documentElement in IE Posted: Mar 24, 2005 8:34 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Kevin Dangoor.
Original Post: document.body vs. document.documentElement in IE
Feed Title: Blue Sky On Mars
Feed URL: http://www.blueskyonmars.com/feed/?cat=8%2C13%2C14
Feed Description: Kevin Dangoor's Weblog of Technology, Entertainment and Life - Java only feed. For all articles, check out http://www.blueskyonmars.com
Latest Java Buzz Posts
Latest Java Buzz Posts by Kevin Dangoor
Latest Posts From Blue Sky On Mars

Advertisement

Ahh, cross-browser fun. Even when you're only supporting very recent browsers (my targets are IE5.5+, Moz/Firefox and Safari), there's always cross-browser joy to be had. I was positioning a div in response to a click, and it worked just dandy in Firefox, but gave an error in IE. I was using event.pageX and event.pageY, which IE knows nothing about. I found many references that said to use event.clientX+document.body.scrollLeft, but it was clear that document.body.scrollLeft was always zero. I finally found the answer here: Event handling in the DOM Part 2- Page 3/4

For IE, the above code adds the scroll offset values of both the HTML tag (represented by document.documentElement) and the BODY tag (represented by document.body). This is because IE 5.5 uses the BODY as a base for rendering and measuring offsets, as does IE 6 when in compatibility mode. But in standards-compliant mode IE 6 instead uses the HTML tag as a base.

So, if you want the document position of an event, the formula is: x = event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft. (y is left as an exercise for the reader).

Read: document.body vs. document.documentElement in IE

Topic: Learning via Unit Tests Previous Topic   Next Topic Topic: My life by Basecamp

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use