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 2015年7月.
documentElement は Document インターフェイスの読み取り専用プロパティで、 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①> |