NodeIterator

  • Revision slug: Web/API/NodeIterator
  • Revision title: NodeIterator
  • Revision id: 450593
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{ DomRef() }}

The NodeIterator interface represents an iterator over the members of a list of the nodes in a subtree of the DOM. The nodes will be returned in document order.

A NodeIterator can be created using the {{domxref("Document.createNodeIterator()")}} method, as follows:

var nodeIterator = document.createNodeIterator(root, whatToShow, filter);

Properties

This interface doesn't inherit any property.

{{domxref("NodeIterator.root")}} {{readonlyInline}}
Returns a {{domxref("Node")}} representing the root node as specified when the NodeIterator was created.
{{domxref("NodeIterator.whatToShow")}} {{readonlyInline}}
Returns an unsigned long being a constant describing the type of {{domxref("Node")}} to be presented. Non-matching nodes are skipped, but their children may be included, if relevant. The possible values are:
{{domxref("NodeIterator.filter")}} {{readonlyInline}}
...
{{domxref("NodeIterator.expandEntityReferences")}} {{readonlyInline}} {{obsolete_inline}}
...
{{domxref("NodeIterator.referenceNode")}} {{readonlyInline}} {{experimental_inline() }}
...
{{domxref("NodeIterator.pointerBeforeReferenceNode")}} {{readonlyInline}} {{ experimental_inline() }}
...

Methods

This interface doesn't inherit any method.

{{domxref("NodeIterator.detach()")}} {{deprecated_inline()}}
This operation is a no-op. It doesn't do anything. Previously it was telling the engine that the NodeIterator was no more used, but this is now useless.
{{domxref("NodeIterator.previousNode()")}}
Returns the previous {{domxref("Node")}} in the document, or null if there are none.
{{domxref("NodeIterator.nextNode()")}}
Returns the next {{domxref("Node")}} in the document, or null if there are none.

Specifications

Specification Status Comment
{{SpecName('DOM WHATWG', '#nodeiterator', 'NodeIterator')}} {{Spec2('DOM WHATWG')}} Added the properties referenceNode and pointerBeforeReferenceNode.
Removed the property expandEntityReferences.
The method detach() has been changed to be a no-op.
The methods previousNode() and nextNode() don't raise an exception any more.
{{SpecName('DOM2 Traversal_Range', 'traversal.html#Iterator-overview', 'NodeIterator')}} {{Spec2('DOM2 Traversal_Range')}} Initial definition.

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 {{CompatGeckoDesktop("1.9.1")}} 9.0 9.0 3.0
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatGeckoMobile("1.9.1")}} {{CompatVersionUnknown}} 9.0 3.0

See also

  • The creator method: {{domxref("Document.createNodeIterator()")}}.
  • Related interfaces: {{domxref("NodeFilter")}}, {{domxref("TreeWalker")}}.

Revision Source

<p>{{ DomRef() }}</p>
<p>The <strong><code>NodeIterator</code></strong> interface represents an iterator over the members of a list of the nodes in a subtree of the DOM. The nodes will be returned in document order.</p>
<p>A <code>NodeIterator</code> can be created using the {{domxref("Document.createNodeIterator()")}} method, as follows:</p>
<pre class="brush: js">
var nodeIterator = document.createNodeIterator(<em>root</em>, <em>whatToShow</em>, <em>filter</em>);</pre>
<h2 id="Properties" name="Properties">Properties</h2>
<p><em>This interface doesn't inherit any property.</em></p>
<dl>
  <dt>
    {{domxref("NodeIterator.root")}} {{readonlyInline}}</dt>
  <dd>
    Returns a {{domxref("Node")}} representing the root node as specified when the <code>NodeIterator</code> was created.</dd>
  <dt>
    {{domxref("NodeIterator.whatToShow")}} {{readonlyInline}}</dt>
  <dd>
    Returns an <code>unsigned long</code> being a constant describing the type of {{domxref("Node")}} to be presented. Non-matching nodes are skipped, but their children may be included, if relevant. The possible values are:</dd>
  <dt>
    {{domxref("NodeIterator.filter")}} {{readonlyInline}}</dt>
  <dd>
    ...</dd>
  <dt>
    {{domxref("NodeIterator.expandEntityReferences")}} {{readonlyInline}} {{obsolete_inline}}</dt>
  <dd>
    ...</dd>
  <dt>
    {{domxref("NodeIterator.referenceNode")}} {{readonlyInline}} {{experimental_inline() }}</dt>
  <dd>
    ...</dd>
  <dt>
    {{domxref("NodeIterator.pointerBeforeReferenceNode")}} {{readonlyInline}} {{ experimental_inline() }}</dt>
  <dd>
    ...</dd>
</dl>
<h2 id="Methods" name="Methods">Methods</h2>
<p><em>This interface doesn't inherit any method.</em></p>
<dl>
  <dt>
    {{domxref("NodeIterator.detach()")}} {{deprecated_inline()}}</dt>
  <dd>
    This operation is a no-op. It doesn't do anything. Previously it was telling the engine that the <code>NodeIterator</code> was no more used, but this is now useless.</dd>
  <dt>
    {{domxref("NodeIterator.previousNode()")}}</dt>
  <dd>
    Returns the previous {{domxref("Node")}} in the document, or <code>null</code> if there are none.</dd>
  <dt>
    {{domxref("NodeIterator.nextNode()")}}</dt>
  <dd>
    Returns the next {{domxref("Node")}} in the document, or <code>null</code> if there are none.</dd>
</dl>
<h2 id="Specification" name="Specification">Specifications</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', '#nodeiterator', 'NodeIterator')}}</td>
      <td>{{Spec2('DOM WHATWG')}}</td>
      <td>Added the properties <code>referenceNode</code> and <code>pointerBeforeReferenceNode</code>.<br />
        Removed the property <code>expandEntityReferences</code>.<br />
        The method <code>detach()</code> has been changed to be a no-op.<br />
        The methods <code>previousNode()</code> and <code>nextNode()</code> don't raise an exception any more.</td>
    </tr>
    <tr>
      <td>{{SpecName('DOM2 Traversal_Range', 'traversal.html#Iterator-overview', 'NodeIterator')}}</td>
      <td>{{Spec2('DOM2 Traversal_Range')}}</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>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td><code>1.0</code></td>
        <td>{{CompatGeckoDesktop("1.9.1")}}</td>
        <td>9.0</td>
        <td>9.0</td>
        <td>3.0</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</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatGeckoMobile("1.9.1")}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>9.0</td>
        <td>3.0</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_also">See also</h2>
<ul>
  <li>The creator method: {{domxref("Document.createNodeIterator()")}}.</li>
  <li>Related interfaces: {{domxref("NodeFilter")}}, {{domxref("TreeWalker")}}.</li>
</ul>
Revert to this revision