NodeIterator.whatToShow

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

Revision Content

{{ DomRef("NodeIterator") }}

The NodeIterator.whatToShow property represents an unsigned integer representing a bitmask signifying what types of nodes should be returned by the {{domxref("NodeIterator")}}

Syntax

var nodeTypes = nodeIterator.whatToShow;

The values that can be combined to form the bitmap are:

Constant Numerical value Description
NodeFilter.SHOW_ALL -1 (that is the max value of unsigned long) Shows all nodes.
NodeFilter.SHOW_ATTRIBUTE {{deprecated_inline}} 2 Shows attribute {{ domxref("Attr") }} nodes. This is meaningful only when creating a {{ domxref("NodeIterator") }} or {{ domxref("TreeWalker") }} with an {{ domxref("Attr") }} node as its root; in this case, it means that the attribute node will appear in the first position of the iteration or traversal. Since attributes are never children of other nodes, they do not appear when traversing over the document tree.
NodeFilter.SHOW_CDATA_SECTION {{deprecated_inline}} 8 Shows {{ domxref("CDATASection") }} nodes.
NodeFilter.SHOW_COMMENT 128 Shows {{ domxref("Comment") }} nodes.
NodeFilter.SHOW_DOCUMENT 256 Shows {{ domxref("Document") }} nodes.
NodeFilter.SHOW_DOCUMENT_FRAGMENT 1024 Shows {{ domxref("DocumentFragment") }} nodes.
NodeFilter.SHOW_DOCUMENT_TYPE 512 Shows {{ domxref("DocumentType") }} nodes.
NodeFilter.SHOW_ELEMENT 1 Shows {{ domxref("Element") }} nodes.
NodeFilter.SHOW_ENTITY {{deprecated_inline}} 32 Shows {{ domxref("Entity") }} nodes. This is meaningful only when creating a {{ domxref("NodeIterator") }} or {{ domxref("TreeWalker") }} with an {{ domxref("Entity") }} node as its root; in this case, it means that the {{ domxref("Entity") }} node will appear in the first position of the traversal. Since entities are not part of the document tree, they do not appear when traversing over the document tree.
NodeFilter.SHOW_ENTITY_REFERENCE {{deprecated_inline}} 16 Shows {{ domxref("EntityReference") }} nodes.
NodeFilter.SHOW_NOTATION {{deprecated_inline}} 2048 Shows {{ domxref("Notation") }} nodes. This is meaningful only when creating a {{ domxref("NodeIterator") }} or {{ domxref("TreeWalker") }} with a {{ domxref("Notation") }} node as its root; in this case, it means that the {{ domxref("Notation") }} node will appear in the first position of the traversal. Since entities are not part of the document tree, they do not appear when traversing over the document tree.
NodeFilter.SHOW_PROCESSING_INSTRUCTION 64 Shows {{ domxref("ProcessingInstruction") }} nodes.
NodeFilter.SHOW_TEXT 4 Shows {{ domxref("Text") }} nodes.

Example

var nodeIterator = document.createNodeIterator(
    document.body,
    NodeFilter.SHOW_ELEMENT + NodeFilter.SHOW_COMMENT + NodeFilter.SHOW_TEXT,
    { acceptNode: function(node) { return NodeFilter.FILTER_ACCEPT; } },
    false
);
if( (nodeIterator.whatToShow == NodeFilter.SHOW_ALL) ||
    (nodeIterator.whatToShow % (NodeFilter.SHOW_COMMENT*2)) >= NodeFilter.SHOW_COMMENT) {
    // nodeIterator will show comments
}

Specifications

Specification Status Comment
{{SpecName('DOM WHATWG', '#nodeiterator', 'NodeIterator')}} {{Spec2('DOM WHATWG')}} No change from {{SpecName('DOM2 Traversal_Range')}}.
{{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 interface this property belongs to: {{domxref("NodeIterator")}}.

Revision Source

<p>{{ DomRef("NodeIterator") }}</p>
<p>The <strong><code>NodeIterator.whatToShow</code></strong> property represents an <code>unsigned integer</code> representing a bitmask signifying what types of nodes should be returned by the {{domxref("NodeIterator")}}</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox">
var nodeTypes = <em>nodeIterator</em>.whatToShow;
</pre>
<p>The values that can be combined to form the bitmap are:</p>
<table class="standard-table">
  <tbody>
    <tr>
      <td class="header">Constant</td>
      <td class="header">Numerical value</td>
      <td class="header">Description</td>
    </tr>
    <tr>
      <td><code>NodeFilter.SHOW_ALL</code></td>
      <td><code>-1</code> (that is the max value of <code>unsigned long</code>)</td>
      <td>Shows all nodes.</td>
    </tr>
    <tr>
      <td><code><code>NodeFilter.</code>SHOW_ATTRIBUTE</code> {{deprecated_inline}}</td>
      <td><code>2</code></td>
      <td>Shows attribute {{ domxref("Attr") }} nodes. This is meaningful only when creating a {{ domxref("NodeIterator") }} or {{ domxref("TreeWalker") }} with an {{ domxref("Attr") }} node as its root; in this case, it means that the attribute node will appear in the first position of the iteration or traversal. Since attributes are never children of other nodes, they do not appear when traversing over the document tree.</td>
    </tr>
    <tr>
      <td><code><code>NodeFilter.</code>SHOW_CDATA_SECTION</code> {{deprecated_inline}}</td>
      <td><code>8</code></td>
      <td>Shows {{ domxref("CDATASection") }}&nbsp;nodes.</td>
    </tr>
    <tr>
      <td><code><code>NodeFilter.</code>SHOW_COMMENT</code></td>
      <td><code>128</code></td>
      <td>Shows {{ domxref("Comment") }}&nbsp;nodes.</td>
    </tr>
    <tr>
      <td><code><code>NodeFilter.</code>SHOW_DOCUMENT</code></td>
      <td><code>256</code></td>
      <td>Shows {{ domxref("Document") }}&nbsp;nodes.</td>
    </tr>
    <tr>
      <td><code><code>NodeFilter.</code>SHOW_DOCUMENT_FRAGMENT</code></td>
      <td><code>1024</code></td>
      <td>Shows {{ domxref("DocumentFragment") }}&nbsp;nodes.</td>
    </tr>
    <tr>
      <td><code><code>NodeFilter.</code>SHOW_DOCUMENT_TYPE</code></td>
      <td><code>512</code></td>
      <td>Shows {{ domxref("DocumentType") }}&nbsp;nodes.</td>
    </tr>
    <tr>
      <td><code><code>NodeFilter.</code>SHOW_ELEMENT</code></td>
      <td><code>1</code></td>
      <td>Shows {{ domxref("Element") }}&nbsp;nodes.</td>
    </tr>
    <tr>
      <td><code><code>NodeFilter.</code>SHOW_ENTITY</code> {{deprecated_inline}}</td>
      <td><code>32</code></td>
      <td>Shows {{ domxref("Entity") }}&nbsp;nodes. This is meaningful only when creating a {{ domxref("NodeIterator") }} or {{ domxref("TreeWalker") }} with an {{ domxref("Entity") }} node as its root; in this case, it means that the {{ domxref("Entity") }} node will appear in the first position of the traversal. Since entities are not part of the document tree, they do not appear when traversing over the document tree.</td>
    </tr>
    <tr>
      <td><code><code>NodeFilter.</code>SHOW_ENTITY_REFERENCE</code> {{deprecated_inline}}</td>
      <td><code>16</code></td>
      <td>Shows {{ domxref("EntityReference") }}&nbsp;nodes.</td>
    </tr>
    <tr>
      <td><code><code><code>NodeFilter.</code></code>SHOW_NOTATION</code> {{deprecated_inline}}</td>
      <td><code>2048</code></td>
      <td>Shows {{ domxref("Notation") }} nodes. This is meaningful only when creating a {{ domxref("NodeIterator") }} or {{ domxref("TreeWalker") }} with a {{ domxref("Notation") }} node as its root; in this case, it means that the {{ domxref("Notation") }} node will appear in the first position of the traversal. Since entities are not part of the document tree, they do not appear when traversing over the document tree.</td>
    </tr>
    <tr>
      <td><code><code>NodeFilter.</code>SHOW_PROCESSING_INSTRUCTION</code></td>
      <td><code>64</code></td>
      <td>Shows {{ domxref("ProcessingInstruction") }}&nbsp;nodes.</td>
    </tr>
    <tr>
      <td><code><code>NodeFilter.</code>SHOW_TEXT</code></td>
      <td><code>4</code></td>
      <td>Shows {{ domxref("Text") }}&nbsp;nodes.</td>
    </tr>
  </tbody>
</table>
<h2 id="Example" name="Example">Example</h2>
<pre class="brush: js">
var nodeIterator = document.createNodeIterator(
    document.body,
    NodeFilter.SHOW_ELEMENT + NodeFilter.SHOW_COMMENT + NodeFilter.SHOW_TEXT,
    { acceptNode: function(node) { return NodeFilter.FILTER_ACCEPT; } },
    false
);
if( (nodeIterator.whatToShow == NodeFilter.SHOW_ALL) ||
    (nodeIterator.whatToShow&nbsp;% (NodeFilter.SHOW_COMMENT*2)) &gt;= NodeFilter.SHOW_COMMENT) {
    // nodeIterator will show comments
}
</pre>
<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>No change from {{SpecName('DOM2 Traversal_Range')}}.</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 interface this property belongs to: {{domxref("NodeIterator")}}.</li>
</ul>
Revert to this revision