blob: aa3f5db82d920e10c821f28cb448dcda23e4eaf3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
---
title: Document.documentElement
slug: Web/API/Document/documentElement
translation_of: Web/API/Document/documentElement
---
<p>{{ ApiRef("DOM") }}</p>
<p><code><strong>Document.documentElement</strong></code> 會回傳目前文件({{domxref("document")}})中的根元素({{domxref("Element")}}),如:HTML 文件中的 <code><html></code> 元素。</p>
<h2 id="Syntax" name="Syntax">語法</h2>
<pre class="syntaxbox">var <em>element</em> = document.documentElement;
</pre>
<h2 id="Example" name="Example">範例</h2>
<pre class="brush: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]
}</pre>
<h2 id="Notes" name="Notes">備註</h2>
<p>對於所有非空的 HTML 文件, <code>document.documentElement</code> 將會是一個 {{HTMLElement("html")}} 元素 ; 對於所有非空的 XML 文件,<code>document.documentElement</code> 則會是文件的根元素。</p>
<h2 id="Specification" name="Specification">規範</h2>
<table class="spectable standard-table">
<tbody>
<tr>
<th scope="col">規範</th>
<th scope="col">狀態</th>
<th scope="col"> 備註</th>
</tr>
<tr>
<td>{{SpecName('DOM2 Core','core.html#ID-87CD092','Document.documentElement')}}</td>
<td>{{Spec2('DOM2 Core')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('DOM3 Core','core.html#ID-87CD092','Document.documentElement')}}</td>
<td>{{Spec2('DOM3 Core')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('DOM4','#dom-document-documentelement','Document.documentElement')}}</td>
<td>{{Spec2('DOM4')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('DOM WHATWG','#dom-document-documentelement','Document.documentElement')}}</td>
<td>{{Spec2('DOM WHATWG')}}</td>
<td> </td>
</tr>
</tbody>
</table>
|