Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1074552 of ParentNode

  • Revision slug: Web/API/ParentNode
  • Revision title: ParentNode
  • Revision id: 1074552
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment bug 911477
Tags: 

Revision Content

{{APIRef("DOM")}}

The ParentNode interface contains methods that are particular to {{domxref("Node")}} objects that can have children.

ParentNode is a raw interface and no object of this type can be created; it is implemented by {{domxref("Element")}}, {{domxref("Document")}}, and {{domxref("DocumentFragment")}} objects.

Properties

{{ domxref("ParentNode.children") }} {{experimental_inline}} {{readonlyInline}}
Returns a live {{domxref("HTMLCollection")}} containing all objects of type {{domxref("Element")}} that are children of this ParentNode.
{{ domxref("ParentNode.firstElementChild") }} {{experimental_inline}} {{readonlyInline}}
Returns the {{domxref("Element")}} that is the first child of this ParentNode, or null if there is none.
{{ domxref("ParentNode.lastElementChild") }} {{experimental_inline}} {{readonlyInline}}
Returns the {{domxref("Element")}} that is the last child of this ParentNode, or null if there is none.
{{ domxref("ParentNode.childElementCount") }} {{experimental_inline}} {{readonlyInline}}
Returns an unsigned long giving the amount of children that the object has.

Methods

{{ domxref("ParentNode.append()") }} {{experimental_inline}}
Inserts a set of {{domxref("Node")}} objects or {{domxref("DOMString")}} objects after the last child of the ParentNode. {{domxref("DOMString")}} objects are inserted as equivalent {{domxref("Text")}} nodes.
{{ domxref("ParentNode.prepend()") }} {{experimental_inline}}
Inserts a set of {{domxref("Node")}} objects or {{domxref("DOMString")}} objects before the first child of the ParentNode. {{domxref("DOMString")}} objects are inserted as equivalent {{domxref("Text")}} nodes.

Specification

Specification Status Comment
{{SpecName('DOM WHATWG', '#dom-parentnode-firstelementchild', 'ParentNode.firstElementChild')}} {{Spec2('DOM WHATWG')}} Splitted the ElementTraversal interface in {{domxref("ChildNode")}} and ParentNode. The firstElementChild, lastElementChild, and childElementCount properties are now defined on the latter.
The {{domxref("Document")}} and {{domxref("DocumentFragment")}} implemented the new interfaces.
Added the children property.
Added the append() and prepend() methods.
{{SpecName('Element Traversal', '#interface-elementTraversal', 'ElementTraversal')}} {{Spec2('Element Traversal')}} Added the initial definition of its properties to the ElementTraversal pure interface and use it on {{domxref("Element")}}.

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (on {{domxref("Element")}}) 1.0 {{CompatGeckoDesktop("1.9.1")}} 9.0 [1] 10.0 4.0
Support on {{domxref("Document")}} and {{domxref("DocumentFragment")}} {{experimental_inline}} 29.0 {{CompatGeckoDesktop(25)}} {{CompatNo}} 16.0 {{CompatNo}}
append() and prepend() {{experimental_inline}} {{CompatNo}} {{CompatGeckoDesktop(49)}} {{CompatNo}} {{CompatNo}} {{CompatNo}}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (on {{domxref("Element")}}) {{CompatVersionUnknown}} {{CompatGeckoMobile("1.9.1")}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
Support on {{domxref("Document")}} and {{domxref("DocumentFragment")}} {{experimental_inline}} {{CompatVersionUnknown}} {{CompatGeckoMobile(25)}} {{CompatNo}} 16.0 {{CompatNo}}
append() and prepend() {{experimental_inline}} {{CompatNo}} {{CompatGeckoMobile(49)}} {{CompatNo}} {{CompatNo}} {{CompatNo}}

[1] Internet Explorer 6, 7 and 8 supported it, but erroneously returns {{domxref("Comment")}} nodes as part of the results.

See also

  • The {{domxref("ChildNode")}} pure interface.
  • Object types implementing this pure interface: {{domxref("Document")}}, {{domxref("Element")}}, and {{domxref("DocumentFragment")}}.

Revision Source

<div>{{APIRef("DOM")}}</div>

<p>The <code><strong>ParentNode</strong></code> interface contains methods that are particular to {{domxref("Node")}} objects that can have children.</p>

<p><code>ParentNode</code> is a raw interface and no object of this type can be created; it is implemented by {{domxref("Element")}}, {{domxref("Document")}}, and {{domxref("DocumentFragment")}} objects.</p>

<h2 id="Properties">Properties</h2>

<dl>
 <dt>{{ domxref("ParentNode.children") }} {{experimental_inline}} {{readonlyInline}}</dt>
 <dd>Returns a live {{domxref("HTMLCollection")}} containing all objects of type {{domxref("Element")}} that are children of this <code>ParentNode</code>.</dd>
 <dt>{{ domxref("ParentNode.firstElementChild") }} {{experimental_inline}} {{readonlyInline}}</dt>
 <dd>Returns the {{domxref("Element")}} that is the first child of this <code>ParentNode</code>, or <code>null</code> if there is none.</dd>
 <dt>{{ domxref("ParentNode.lastElementChild") }} {{experimental_inline}} {{readonlyInline}}</dt>
 <dd>Returns the {{domxref("Element")}} that is the last child of this <code>ParentNode</code>, or <code>null</code> if there is none.</dd>
 <dt>{{ domxref("ParentNode.childElementCount") }} {{experimental_inline}} {{readonlyInline}}</dt>
 <dd>Returns an <code>unsigned long</code> giving the amount of children that the object has.</dd>
</dl>

<h2 id="Methods">Methods</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>
</dl>

<h2 id="Specification">Specification</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>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.<br />
    Added the <code>append()</code> and <code>prepend()</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 use it on {{domxref("Element")}}.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</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>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>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>{{CompatNo}}</td>
   <td>{{CompatGeckoDesktop(49)}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</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)}}</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>{{CompatNo}}</td>
   <td>{{CompatGeckoMobile(49)}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</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="See_also">See also</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>
Revert to this revision