aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/api/parentnode
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-tw/web/api/parentnode')
-rw-r--r--files/zh-tw/web/api/parentnode/children/index.html152
-rw-r--r--files/zh-tw/web/api/parentnode/firstelementchild/index.html95
-rw-r--r--files/zh-tw/web/api/parentnode/index.html166
3 files changed, 413 insertions, 0 deletions
diff --git a/files/zh-tw/web/api/parentnode/children/index.html b/files/zh-tw/web/api/parentnode/children/index.html
new file mode 100644
index 0000000000..f9f6c76115
--- /dev/null
+++ b/files/zh-tw/web/api/parentnode/children/index.html
@@ -0,0 +1,152 @@
+---
+title: ParentNode.children
+slug: Web/API/ParentNode/children
+translation_of: Web/API/ParentNode/children
+---
+<p>{{ APIRef("DOM") }}</p>
+
+<p><code><strong>Node.children</strong></code> 唯讀屬性會回傳一個 <code>Node</code> 之子{{domxref("Element","元素")}}的動態(live){{domxref("HTMLCollection")}}。</p>
+
+<h2 id="語法">語法</h2>
+
+<pre class="syntaxbox">var <em>children</em> = <em>node</em>.children;</pre>
+
+<p><code><em>children</em></code> 是一個 {{ domxref("HTMLCollection") }},為一個有順序性、由 <em><code>node</code></em> 中的 DOM 子元素所組成的集合。假如沒有子元素,則 <code><em>children</em></code> 內便不包含任何元素,且 <code>length</code> 為 <code>0</code>。</p>
+
+<h2 id="範例">範例</h2>
+
+<pre class="brush: js">var foo = document.getElementById('foo');
+for (var i = 0; i &lt; foo.children.length; i++) {
+ console.log(foo.children[i].tagName);
+}
+</pre>
+
+<h2 id="Polyfill">Polyfill</h2>
+
+<pre class="brush: js">// Overwrites native 'children' prototype.
+// Adds Document &amp; DocumentFragment support for IE9 &amp; Safari.
+// Returns array instead of HTMLCollection.
+;(function(constructor) {
+ if (constructor &amp;&amp;
+ constructor.prototype &amp;&amp;
+ constructor.prototype.children == null) {
+ Object.defineProperty(constructor.prototype, 'children', {
+ get: function() {
+ var i = 0, node, nodes = this.childNodes, children = [];
+ while (node = nodes[i++]) {
+ if (node.nodeType === 1) {
+ children.push(node);
+ }
+ }
+ return children;
+ }
+ });
+ }
+})(window.Node || window.Element);
+</pre>
+
+<h2 id="規範">規範</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('DOM WHATWG', '#dom-parentnode-children', 'ParentNode.children')}}</td>
+ <td>{{Spec2('DOM WHATWG')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
+
+<p>{{ CompatibilityTable() }}</p>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Edge</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support (on {{domxref("Element")}})</td>
+ <td>1.0</td>
+ <td>{{CompatGeckoDesktop("1.9.1")}}</td>
+ <td>9.0 [1]</td>
+ <td>38.0</td>
+ <td>10.0</td>
+ <td>4.0</td>
+ </tr>
+ <tr>
+ <td>Support on {{domxref("Document")}} and {{domxref("DocumentFragment")}} {{experimental_inline}}</td>
+ <td>29.0</td>
+ <td>{{CompatGeckoDesktop("25.0")}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>16.0</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ <tr>
+ <td>Support on {{domxref("SVGElement")}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support (on {{domxref("Element")}})</td>
+ <td>{{ CompatVersionUnknown() }}</td>
+ <td>{{CompatGeckoMobile("1.9.1")}}</td>
+ <td>{{ CompatVersionUnknown() }}</td>
+ <td>{{ CompatVersionUnknown() }}</td>
+ <td>{{ CompatVersionUnknown() }}</td>
+ </tr>
+ <tr>
+ <td>Support on {{domxref("Document")}} and {{domxref("DocumentFragment")}} {{experimental_inline}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoMobile("25.0")}}</td>
+ <td>{{CompatNo}}</td>
+ <td>16.0</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<p>[1] Internet Explorer 6, 7 and 8 supported it, but erroneously includes {{domxref("Comment")}} nodes.</p>
+
+<h2 id="參見">參見</h2>
+
+<ul>
+ <li>The {{domxref("ParentNode")}} and {{domxref("ChildNode")}} interfaces.</li>
+ <li>
+ <div class="syntaxbox">Object types implementing this interface: {{domxref("Document")}}, {{domxref("Element")}}, and {{domxref("DocumentFragment")}}.</div>
+ </li>
+</ul>
diff --git a/files/zh-tw/web/api/parentnode/firstelementchild/index.html b/files/zh-tw/web/api/parentnode/firstelementchild/index.html
new file mode 100644
index 0000000000..4fa9722123
--- /dev/null
+++ b/files/zh-tw/web/api/parentnode/firstelementchild/index.html
@@ -0,0 +1,95 @@
+---
+title: ParentNode.firstElementChild
+slug: Web/API/ParentNode/firstElementChild
+translation_of: Web/API/ParentNode/firstElementChild
+---
+<p>{{ APIRef("DOM") }}</p>
+
+<p><strong><code>ParentNode.firstElementChild</code></strong> 介面會會返回 <code>ParentNode</code>的第一個子元素(唯讀) ,如果該節點沒有子節點則返回<code>null</code>。</p>
+
+<div class="note">
+<p>This property was initially defined in the {{domxref("ElementTraversal")}} pure interface. As this interface contained two distinct set of properties, one aimed at {{domxref("Node")}} that have children, one at those that are children, they have been moved into two separate pure interfaces, {{domxref("ParentNode")}} and {{domxref("ChildNode")}}. In this case, <code>firstElementChild</code> moved to {{domxref("ParentNode")}}. This is a fairly technical change that shouldn't affect compatibility.</p>
+</div>
+
+<h2 id="Syntax_and_values" name="Syntax_and_values">語法</h2>
+
+<pre class="syntaxbox">var <em>element</em> = node.firstElementChild;
+</pre>
+
+<h2 id="Example" name="Example">範例</h2>
+
+<pre class="brush: html">&lt;ul id="foo"&gt;
+ &lt;li&gt;First (1)&lt;/li&gt;
+ &lt;li&gt;Second (2)&lt;/li&gt;
+ &lt;li&gt;Third (3)&lt;/li&gt;
+&lt;/ul&gt;
+
+&lt;script&gt;
+var foo = document.getElementById('foo');
+// yields: First (1)
+console.log(foo.firstElementChild.textContent);
+&lt;/script&gt;
+</pre>
+
+<h2 id="適用於IE8_IE9_和_Safari的Polyfill">適用於IE8, IE9 和 Safari的Polyfill</h2>
+
+<pre class="brush: js">// Overwrites native 'firstElementChild' prototype.
+// Adds Document &amp; DocumentFragment support for IE9 &amp; Safari.
+;(function(constructor) {
+ if (constructor &amp;&amp;
+ constructor.prototype &amp;&amp;
+ constructor.prototype.firstElementChild == null) {
+ Object.defineProperty(constructor.prototype, 'firstElementChild', {
+ get: function() {
+ var node, nodes = this.childNodes, i = 0;
+ while (node = nodes[i++]) {
+ if (node.nodeType === 1) {
+ return node;
+ }
+ }
+ return null;
+ }
+ });
+ }
+})(window.Node || window.Element);
+</pre>
+
+<h2 id="規範">規範</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('DOM WHATWG', '#dom-parentnode-firstelementchild', 'ParentNode.firstElementChild')}}</td>
+ <td>{{Spec2('DOM WHATWG')}}</td>
+ <td>Split the <code>ElementTraversal</code> interface in {{domxref("ChildNode")}} and <code>ParentNode</code>. This method is now defined on the latter.<br>
+ The {{domxref("Document")}} and {{domxref("DocumentFragment")}} implemented the new interfaces.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('Element Traversal', '#attribute-firstElementChild', 'ElementTraversal.firstElementChild')}}</td>
+ <td>{{Spec2('Element Traversal')}}</td>
+ <td>Added its initial definition to the <code>ElementTraversal</code> pure interface and use it on {{domxref("Element")}}.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
+
+
+
+<p>{{Compat("api.ParentNode.firstElementChild")}}</p>
+
+<h2 id="參見">參見</h2>
+
+<ul>
+ <li>{{domxref("NonDocumentTypeChildNode.nextElementSibling")}}</li>
+ <li>{{domxref("ParentNode.lastElementChild")}}</li>
+ <li>The {{domxref("ParentNode")}} and {{domxref("ChildNode")}} pure interfaces.</li>
+ <li>
+ <div class="syntaxbox">Object types implementing this pure interface: {{domxref("Document")}}, {{domxref("Element")}}, and {{domxref("DocumentFragment")}}.</div>
+ </li>
+</ul>
diff --git a/files/zh-tw/web/api/parentnode/index.html b/files/zh-tw/web/api/parentnode/index.html
new file mode 100644
index 0000000000..f3a37abb2f
--- /dev/null
+++ b/files/zh-tw/web/api/parentnode/index.html
@@ -0,0 +1,166 @@
+---
+title: ParentNode
+slug: Web/API/ParentNode
+translation_of: Web/API/ParentNode
+---
+<div>{{APIRef("DOM")}}</div>
+
+<p><code><strong>ParentNode</strong></code> 介面定義了可以擁有子節點之 {{domxref("Node")}} 物件的方法。</p>
+
+<p><code>ParentNode</code> 是一個原始的介面,且不能以此建立物件實體。{{domxref("Element")}}、{{domxref("Document")}} 及 {{domxref("DocumentFragment")}} 物件皆實作了 <code>ParentNode</code>。</p>
+
+<h2 id="屬性">屬性</h2>
+
+<dl>
+ <dt>{{domxref("ParentNode.children")}} {{experimental_inline}} {{readonlyInline}}</dt>
+ <dd>該屬性會返回一個 {{domxref("HTMLCollection")}} 實例,包括 <code>ParentNode</code>的所有子元素節點,需要特別注意的是:該屬性為<code>唯讀</code>。</dd>
+ <dt>{{domxref("ParentNode.firstElementChild")}} {{experimental_inline}} {{readonlyInline}}</dt>
+ <dd>該屬性會返回 <code>ParentNode</code>的第一個子元素 ,如果該節點沒有子節點則返回<code>null</code>。</dd>
+ <dt>{{domxref("ParentNode.lastElementChild")}} {{experimental_inline}} {{readonlyInline}}</dt>
+ <dd>該屬性會返回 <code>ParentNode</code>的最後一個子元素 ,如果該節點沒有子節點則返回<code>null</code>。</dd>
+ <dt>{{domxref("ParentNode.childElementCount")}} {{experimental_inline}} {{readonlyInline}}</dt>
+ <dd>該屬性會返回一個<code>無符號長整數</code> ,該值表示了該節點的子節點數量。</dd>
+</dl>
+
+<h2 id="方法">方法</h2>
+
+<dl>
+ <dt>{{domxref("ParentNode.append()")}} {{experimental_inline}}</dt>
+ <dd>Inserts a set of {{domxref("Node")}} objects or {{domxref("DOMString")}} objects after the last child of the <code>ParentNode</code>. {{domxref("DOMString")}} objects are inserted as equivalent {{domxref("Text")}} nodes.</dd>
+ <dt>{{domxref("ParentNode.prepend()")}} {{experimental_inline}}</dt>
+ <dd>Inserts a set of {{domxref("Node")}} objects or {{domxref("DOMString")}} objects before the first child of the <code>ParentNode</code>. {{domxref("DOMString")}} objects are inserted as equivalent {{domxref("Text")}} nodes.</dd>
+ <dt>{{domxref("ParentNode.querySelector()")}}</dt>
+ <dd>Returns the first {{domxref("Element")}} with the current element as root that matches the specified group of selectors.</dd>
+ <dt>{{domxref("ParentNode.querySelectorAll()")}}</dt>
+ <dd>Returns a {{domxref("NodeList")}} representing a list of elements with the current element as root that matches the specified group of selectors.</dd>
+</dl>
+
+<h2 id="規範">規範</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('DOM WHATWG', '#parentnode', 'ParentNode')}}</td>
+ <td>{{Spec2('DOM WHATWG')}}</td>
+ <td>Added the <code>append()</code> and <code>prepend()</code> methods.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('DOM4', '#parentnode', 'ParentNode')}}</td>
+ <td>{{Spec2('DOM4')}}</td>
+ <td>Splitted the <code>ElementTraversal</code> interface in {{domxref("ChildNode")}} and <code>ParentNode</code>. The <code>firstElementChild</code>, <code>lastElementChild</code>, and <code>childElementCount</code> properties are now defined on the latter.<br>
+ The {{domxref("Document")}} and {{domxref("DocumentFragment")}} implemented the new interfaces.<br>
+ Added the <code>children</code> property and the <code>querySelector()</code> and <code>querySelectorAll()</code> methods.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('Element Traversal', '#interface-elementTraversal', 'ElementTraversal')}}</td>
+ <td>{{Spec2('Element Traversal')}}</td>
+ <td>Added the initial definition of its properties to the <code>ElementTraversal</code> pure interface and used it on {{domxref("Element")}}.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
+
+<p>{{CompatibilityTable}}</p>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support (on {{domxref("Element")}})</td>
+ <td>{{CompatChrome(1.0)}}</td>
+ <td>{{CompatGeckoDesktop("1.9.1")}}</td>
+ <td>9.0 [1]</td>
+ <td>10.0</td>
+ <td>4.0</td>
+ </tr>
+ <tr>
+ <td>Support on {{domxref("Document")}} and {{domxref("DocumentFragment")}} {{experimental_inline}}</td>
+ <td>{{CompatChrome(29.0)}}</td>
+ <td>{{CompatGeckoDesktop(25)}}</td>
+ <td>{{CompatNo}}</td>
+ <td>16.0</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ <tr>
+ <td><code>append()</code> and <code>prepend()</code> {{experimental_inline}}</td>
+ <td>{{CompatChrome(54.0)}}</td>
+ <td>{{CompatGeckoDesktop(49)}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatOpera(39)}}</td>
+ <td>{{CompatNo}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Android Webview</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ <th>Chrome for Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support (on {{domxref("Element")}})</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoMobile("1.9.1")}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ </tr>
+ <tr>
+ <td>Support on {{domxref("Document")}} and {{domxref("DocumentFragment")}} {{experimental_inline}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatGeckoMobile(25)}}</td>
+ <td>{{CompatNo}}</td>
+ <td>16.0</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ </tr>
+ <tr>
+ <td><code>append()</code> and <code>prepend()</code> {{experimental_inline}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatChrome(54.0)}}</td>
+ <td>{{CompatGeckoMobile(49)}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatOperaMobile(39)}}</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatChrome(54.0)}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<p>[1] Internet Explorer 6, 7 and 8 supported it, but erroneously returns {{domxref("Comment")}} nodes as part of the results.</p>
+
+<h2 id="參見">參見</h2>
+
+<ul>
+ <li>The {{domxref("ChildNode")}} pure interface.</li>
+ <li>
+ <div class="syntaxbox">Object types implementing this pure interface: {{domxref("Document")}}, {{domxref("Element")}}, and {{domxref("DocumentFragment")}}.</div>
+ </li>
+</ul>