Document.documentElement 會回傳目前文件(document)中的根元素(Element),如:HTML 文件中的 <html> 元素。

語法

var element = document.documentElement;

範例

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 則會是文件的根元素。

規範

規範 狀態  備註
Document Object Model (DOM) Level 2 Core Specification
The definition of 'Document.documentElement' in that specification.
Obsolete  
Document Object Model (DOM) Level 3 Core Specification
The definition of 'Document.documentElement' in that specification.
Obsolete  
DOM4
The definition of 'Document.documentElement' in that specification.
Obsolete  
DOM
The definition of 'Document.documentElement' in that specification.
Living Standard  

文件標籤與貢獻者

此頁面的貢獻者: Snailpool, jackblackevo
最近更新: Snailpool,