...

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



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

document.getElementsByTagName('body')[0]
or
document.documentElement

seems to work better than
document.body

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

liorean
03-09-2005, 04: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.

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

liorean
03-09-2005, 04: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.

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

document.documentElement.event

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...

brothercake
03-10-2005, 08: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).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum