View Full Version : is document.body to be deprecated?

03-09-2005, 05:24 PM
I have noticed that in many cases:


seems to work better than

Now, what do u think/know: Is it a trend to replace the document.body as the document referece?

03-09-2005, 05:33 PM
Well, I doubt it'll be deprecated. However, it only exists in HTML DOM, and then only if the document is HTML, not if the document is XHTML. Most things that are typically bound to document.body actually belong on the document.documentElement. (as seen in the differences in ie6 in standards mode versus earlier versions or ie6 in quirks mode)

It's not a good generic way of accessing that element, and use of it is discouraged.

03-09-2005, 05:39 PM
If so... which is the best probable future way to stabilize the document reference?

03-09-2005, 05:42 PM
document.documentElement will always reference the root element of the document, if that's what you're asking for. It depends a bit on what you want to do.

03-09-2005, 06:01 PM
well. hm... for instance


it looks like

document.documentElement.onmousemove = function(){showMousepos(event)}
woun't work as i was expected to...

For the moment i use

<body onmousemove="showMousepos(event)">

to be sure that it will works crossbrowser...

03-10-2005, 09:50 AM
var body = document.getElementsByTagName('body')[0];

body.onmousemove = function ....

It's only the shortcut reference "document.body" that's gone; you just need to create a new one (assuming that body, and not documentElement, is what you want; which in this case it is).