Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

document.documentElement vs document.all

Tags:

javascript

Can anybody tell me the difference between these two JavaScript commands?
Also what is the compatibility of these two across major browsers? I know documentElement is compatible with most browsers.

Thanks

like image 619
farjad Avatar asked Oct 07 '11 22:10

farjad


People also ask

What is the difference between document body and document documentElement?

The document. documentElement property gives you the html element, while the document. body property gives you the body element.

What does document documentElement do?

documentElement returns the Element that is the root element of the document (for example, the <html> element for HTML documents).

Is document all deprecated?

all. Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes.

Is Windows part of Dom?

The window object is not part of the DOM.


2 Answers

document.all is a proprietary Microsoft extension to the W3C-standard.
It's an old function and should not be used anymore!

rfc document.all vs. document.getElementById

like image 42
Tim Avatar answered Oct 04 '22 10:10

Tim


document.documentElement is a reference to the root element of the document, usually the <html> tag.

document.all is a collection type, containing an enumeration of all the children tags within the document. It's IE specific and should be avoided for cross-browser scripts.

document.documentElement is DOM Level 2, so should work in pretty much any major browser these days.

like image 173
Mike Christensen Avatar answered Oct 04 '22 09:10

Mike Christensen