Document: documentElement プロパティ

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

documentElementDocument インターフェイスの読み取り専用プロパティで、 document のルート要素である Element を返します(例えば、HTML 文書の場合は <html> 要素)。

Element オブジェクトです。

js
const rootElement = document.documentElement;
const firstTier = rootElement.childNodes;
// firstTier は <head> や <body> などの
// ルート要素の直接の子である NodeList

for (const child of firstTier) {
  // ルート要素のそれぞれの直接の子に対する処理
}

メモ

空ではない HTML 文章の場合、 documentElement は常に <html> 要素を返します。空ではない XML 文章の場合、 documentElement は常に文章のルート要素である何らかの要素を返します。

仕様書

Specification
DOM
# ref-for-dom-document-documentelement①

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
documentElement

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support