文档: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① |
浏览器兼容性
加载中…