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
The document. documentElement property gives you the html element, while the document. body property gives you the body element.
documentElement returns the Element that is the root element of the document (for example, the <html> element for HTML documents).
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.
The window object is not part of the DOM.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With