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.
語法
var element = document.documentElement;
範例
js
var rootElement = document.documentElement;
var firstTier = rootElement.childNodes;
// firstTier is the NodeList of the direct children of the root element
for (var i = 0; i < firstTier.length; i++) {
// do something with each direct kid of the root element
// as firstTier[i]
}
備註
對於所有非空的 HTML 文件, document.documentElement
將會是一個 <html>
元素 ; 對於所有非空的 XML 文件,document.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.