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

Specification Status Comment
Document Object Model (DOM) Level 2 Core Specification
The definition of 'Document.documentElement' in that specification.
Obsolete
Document Object Model (DOM) Level 3 Core Specification
The definition of 'Document.documentElement' in that specification.
Obsolete
DOM4
The definition of 'Document.documentElement' in that specification.
Obsolete
DOM
The definition of 'Document.documentElement' in that specification.
Living Standard

Document Tags and Contributors

 Last updated by: u_7cc,