TreeWalker.filter

  • Revision slug: Web/API/treeWalker.filter
  • Revision title: TreeWalker.filter
  • Revision id: 453233
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{ DomRef("TreeWalker") }}

The read-only TreeWalker.filter method returns the {{domxref("NodeFilter")}}, the filtering object associated with the TreeWalker.

When creating the TreeWalker, the filter object is passed in as the third parameter, and its method {{domxref("NodeFilter.acceptNode()")}} is called on every single node to determine whether or not to accept it.

Syntax

nodeFilter = treeWalker.filter;

Example

var treeWalker = document.createTreeWalker(
    document.body,
    NodeFilter.SHOW_ELEMENT,
    { acceptNode: function(node) { return NodeFilter.FILTER_ACCEPT; } },
    false
);
nodeFilter = treeWalker.filter; // document.body in this case

Specifications

Specification Status Comment
{{SpecName('DOM WHATWG', '#treeWalker-filter', 'TreeWalker.filter')}} {{Spec2('DOM WHATWG')}} No change from {{SpecName('DOM2 Traversal_Range', )}}
{{SpecName('DOM2 Traversal_Range', 'traversal.html#Traversal-TreeWalker-filter', 'TreeWalker.filter')}} {{Spec2('DOM2 Traversal_Range')}} Initial definition.

Browser compatibility

{{CompatibilityTable}}

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

See also

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

 

Revision Source

<p>{{ DomRef("TreeWalker") }}</p>
<p>The read-only <strong><code>TreeWalker.filter</code></strong> method returns the {{domxref("NodeFilter")}}, the filtering object associated with the <code>TreeWalker</code>.</p>
<p>When creating the <code>TreeWalker</code>, the filter object is passed in as the third parameter, and its method {{domxref("NodeFilter.acceptNode()")}} is called on every single node to determine whether or not to accept it.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox">
<em>nodeFilter</em> = <em>treeWalker</em>.filter;
</pre>
<h2 id="Example" name="Example">Example</h2>
<pre class="brush: js">
var treeWalker = document.createTreeWalker(
    document.body,
    NodeFilter.SHOW_ELEMENT,
    { acceptNode: function(node) { return NodeFilter.FILTER_ACCEPT; } },
    false
);
nodeFilter = treeWalker.filter; // document.body in this case
</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', '#treeWalker-filter', 'TreeWalker.filter')}}</td>
      <td>{{Spec2('DOM WHATWG')}}</td>
      <td>No change from {{SpecName('DOM2 Traversal_Range', )}}</td>
    </tr>
    <tr>
      <td>{{SpecName('DOM2 Traversal_Range', 'traversal.html#Traversal-TreeWalker-filter', 'TreeWalker.filter')}}</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>1.0</td>
        <td>{{CompatGeckoDesktop("1.8.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.8.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.createTreeWalker()")}}.</li>
  <li>Related interfaces: {{domxref("NodeFilter")}}, {{domxref("NodeIterator")}}.</li>
</ul>
<p>&nbsp;</p>
Revert to this revision