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 1129685 of ParentNode.children

  • Revision slug: Web/API/ParentNode/children
  • Revision title: ParentNode.children
  • Revision id: 1129685
  • Created:
  • Creator: vedmack
  • Is current revision? No
  • Comment Strange but true

Revision Content

{{ APIRef("DOM") }}

Node.children is a read-only property that returns a live {{domxref("HTMLCollection")}} of the child elements of Node.

Syntax

var elList = elementNodeReference.children; 

elList is a {{ domxref("HTMLCollection") }}, which is an ordered collection of DOM elements that are children of elementNodeReference. If there are no element children, then elList contains no elements and has a length of 0.

Example

// pEl is a reference to a <p> element
var elementChildren = pEl.children;
for (var i = 0; i < elementChildren.length; i++) {
    console.log(elementChildren[i].tagName);
    // NOTE: elementChildren is a live list, adding or removing children from pEl
    // will change the members of elementChildren immediately
}

Specification

Specification Status Comment
{{SpecName('DOM WHATWG', '#dom-parentnode-children', 'ParentNode.children')}} {{Spec2('DOM WHATWG')}} Initial definition.

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Edge Opera Safari
Basic support (on {{domxref("Element")}}) 1.0 {{CompatGeckoDesktop("1.9.1")}} 9.0 [1]
  {{CompatNo}}
10.0 4.0
Support on {{domxref("Document")}} and {{domxref("DocumentFragment")}} {{experimental_inline}} 29.0 {{CompatGeckoDesktop("25.0")}} {{CompatNo}}
  {{CompatNo}}
16.0 {{CompatNo}}
Support on {{domxref("SVGElement")}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatNo}}
  {{CompatNo}}
{{CompatUnknown}} {{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.0")}} {{CompatNo}} 16.0 {{CompatNo}}

[1] Internet Explorer 6, 7 and 8 supported it, but erroneously includes {{domxref("Comment")}} nodes.

See also

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

Revision Source

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

<p><code><strong>Node.children</strong></code>&nbsp;is a read-only property that returns a live {{domxref("HTMLCollection")}} of the&nbsp;child elements of <code>Node</code>.</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">
var <em>elList</em> = elementNodeReference.children; </pre>

<p><code><var>elList</var></code> is a {{ domxref("HTMLCollection") }}, which is an ordered collection of DOM elements that are children of <code>elementNodeReference</code>. If there are no element children, then <code><var>elList</var></code> contains no elements and has a <code>length</code> of <code>0</code>.</p>

<h2 id="Example">Example</h2>

<pre class="brush: js">
// pEl is a reference to a &lt;p&gt; element
var elementChildren = pEl.children;
for (var i = 0; i &lt; elementChildren.length; i++) {
    console.log(elementChildren[i].tagName);
    // NOTE: elementChildren is a live list, adding or removing children from pEl
&nbsp;   // will change the members of elementChildren immediately
}
</pre>

<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-children', 'ParentNode.children')}}</td>
   <td>{{Spec2('DOM WHATWG')}}</td>
   <td>Initial definition.</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>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>
    <table class="compat-table">
     <tbody>
      <tr>
       <td>&nbsp;</td>
       <td>{{CompatNo}}</td>
      </tr>
     </tbody>
    </table>
   </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>
    <table class="compat-table">
     <tbody>
      <tr>
       <td>&nbsp;</td>
       <td>{{CompatNo}}</td>
      </tr>
     </tbody>
    </table>
   </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>
    <table class="compat-table">
     <tbody>
      <tr>
       <td>&nbsp;</td>
       <td>{{CompatNo}}</td>
      </tr>
     </tbody>
    </table>
   </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="See_also">See also</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>
Revert to this revision