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.
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① |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
documentElement |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
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.