aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/api/nodefilter/index.html
blob: 8e71d48db4e4cc3d3881c9960d2cb33a28c37f05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
---
title: NodeFilter
slug: Web/API/NodeFilter
tags:
  - API
  - DOM
  - Reference
translation_of: Web/API/NodeFilter
---
<div>{{APIRef("DOM")}}</div>

<p><span class="seoSummary"><code><strong>NodeFilter</strong></code> 인터페이스는 {{ domxref("NodeIterator") }}{{ domxref("TreeWalker") }}에서 노드를 거를 때 사용하는 객체를 나타냅니다.</span> <code>NodeFilter</code>는 DOM이나 노드 순회 방법은 알지 못하며, 주어진 필터에 대해 단일 노드를 평가하는 방법만 알 수 있습니다.</p>

<div class="note">
<p>The browser doesn't provide any object implementing this interface. It is the user who is expected to write one, tailoring the <code>acceptNode()</code> method to its needs, and using it with some {{domxref("TreeWalker")}} or {{domxref("NodeIterator")}} objects.</p>
</div>

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

<p><em>This interface neither implements, nor inherits, any properties.</em></p>

<h2 id="Methods">Methods</h2>

<p><em>This interface doesn't inherit any methods.</em></p>

<dl>
 <dt>{{domxref("NodeFilter.acceptNode()")}}</dt>
 <dd>Returns an <code>unsigned short</code> that will be used to tell if a given {{domxref("Node")}} must be accepted or not by the {{ domxref("NodeIterator") }} or {{ domxref("TreeWalker") }} iteration algorithm. This method is expected to be written by the user of a <code>NodeFilter</code>. Possible return values are:
 <table class="standard-table">
  <tbody>
   <tr>
    <td class="header">Constant</td>
    <td class="header">Description</td>
   </tr>
   <tr>
    <td><code>FILTER_ACCEPT</code></td>
    <td>Value returned by the {{ domxref("NodeFilter.acceptNode()") }} method when a node should be accepted.</td>
   </tr>
   <tr>
    <td><code>FILTER_REJECT</code></td>
    <td>Value to be returned by the {{ domxref("NodeFilter.acceptNode()") }} method when a node should be rejected. For {{ domxref("TreeWalker") }}, child nodes are also rejected. For {{ domxref("NodeIterator") }}, this flag is synonymous with FILTER_SKIP.</td>
   </tr>
   <tr>
    <td><code>FILTER_SKIP</code></td>
    <td>Value to be returned by {{ domxref("NodeFilter.acceptNode()") }} for nodes to be skipped by the {{ domxref("NodeIterator") }} or {{ domxref("TreeWalker") }} object. The children of skipped nodes are still considered. This is treated as "skip this node but not its children".</td>
   </tr>
  </tbody>
 </table>
 </dd>
</dl>

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

<pre class="brush: js">var nodeIterator = document.createNodeIterator(
  // Node to use as root
  document.getElementById('someId'),

  // Only consider nodes that are text nodes (nodeType 3)
  NodeFilter.SHOW_TEXT,

  // Object containing the function to use for the acceptNode method
  // of the NodeFilter
    { acceptNode: function(node) {
      // Logic to determine whether to accept, reject or skip node
      // In this case, only accept nodes that have content
      // other than whitespace
      if ( ! /^\s*$/.test(node.data) ) {
        return NodeFilter.FILTER_ACCEPT;
      }
    }
  },
  false
);

// Show the content of every non-empty text node that is a child of root
var node;

while ((node = nodeIterator.nextNode())) {
  alert(node.data);
}
</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', '#interface-nodefilter', 'NodeFilter')}}</td>
   <td>{{Spec2('DOM WHATWG')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('DOM2 Traversal_Range', 'traversal.html#Traversal-NodeFilter', 'NodeFilter')}}</td>
   <td>{{Spec2('DOM2 Traversal_Range')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>



<p>{{Compat("api.NodeFilter")}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>Related interfaces: {{domxref("TreeWalker")}}, {{domxref("NodeIterator")}}.</li>
</ul>