文件:documentElement 屬性
Document 介面的只讀屬性 documentElement 返回 Document 的根元素(例如,對於 HTML 文件,即 <html> 元素)。
值
一個 Element 物件。
示例
js
const rootElement = document.documentElement;
const firstTier = rootElement.childNodes;
// firstTier is a NodeList of the direct children of the root element
// such as <head> and <body>
for (const child of firstTier) {
// do something with each direct child of the root element
}
注意
對於任何非空 HTML 文件,documentElement 始終是 <html> 元素。對於任何非空 XML 文件,documentElement 始終是文件的根元素。
規範
| 規範 |
|---|
| DOM # ref-for-dom-document-documentelement① |
瀏覽器相容性
載入中…