Document.documentElement returns the Element that is the root element of the document (for example, the <html> element for HTML documents).
Syntax
var element = document.documentElement;
Example
var rootElement = document.documentElement;
var firstTier = rootElement.childNodes;
// firstTier is the NodeList of the direct children of the root element
for (var i = 0; i < firstTier.length; i++) {
// do something with each direct kid of the root element
// as firstTier[i]
}
Notes
For any non-empty HTML document, document.documentElement will always be an <html> element. For any non-empty XML document, document.documentElement will always be whatever element is the root element of the document.
Specifications
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
documentElement | Chrome Full support 1 | Edge Full support 12 | Firefox Full support Yes | IE Full support 5 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support Yes | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
Legend
- Full support
- Full support