diff --git a/files/en-us/_redirects.txt b/files/en-us/_redirects.txt index a7736ed8d6c2e3d..f01bf46c517eb5c 100644 --- a/files/en-us/_redirects.txt +++ b/files/en-us/_redirects.txt @@ -1571,7 +1571,7 @@ /en-US/docs/DOM/Node.removeChild /en-US/docs/Web/API/Node/removeChild /en-US/docs/DOM/Node.replaceChild /en-US/docs/Web/API/Node/replaceChild /en-US/docs/DOM/Node.textContent /en-US/docs/Web/API/Node/textContent -/en-US/docs/DOM/NodeFilter /en-US/docs/Web/API/NodeFilter +/en-US/docs/DOM/NodeFilter /en-US/docs/Web/API/Document/createNodeIterator /en-US/docs/DOM/NodeIterator /en-US/docs/Web/API/NodeIterator /en-US/docs/DOM/NodeIterator.detach /en-US/docs/Web/API/NodeIterator/detach /en-US/docs/DOM/NodeIterator.filter /en-US/docs/Web/API/NodeIterator/filter @@ -2904,7 +2904,7 @@ /en-US/docs/Document_Object_Model_(DOM)/Node.removeChild /en-US/docs/Web/API/Node/removeChild /en-US/docs/Document_Object_Model_(DOM)/Node.replaceChild /en-US/docs/Web/API/Node/replaceChild /en-US/docs/Document_Object_Model_(DOM)/Node.textContent /en-US/docs/Web/API/Node/textContent -/en-US/docs/Document_Object_Model_(DOM)/NodeFilter /en-US/docs/Web/API/NodeFilter +/en-US/docs/Document_Object_Model_(DOM)/NodeFilter /en-US/docs/Web/API/Document/createNodeIterator /en-US/docs/Document_Object_Model_(DOM)/NodeIterator /en-US/docs/Web/API/NodeIterator /en-US/docs/Document_Object_Model_(DOM)/NodeIterator.detach /en-US/docs/Web/API/NodeIterator/detach /en-US/docs/Document_Object_Model_(DOM)/NodeIterator.filter /en-US/docs/Web/API/NodeIterator/filter @@ -8817,7 +8817,9 @@ /en-US/docs/Web/API/Node/outerText /en-US/docs/Web/API/HTMLElement/outerText /en-US/docs/Web/API/Node/prefix /en-US/docs/Web/API/Element/prefix /en-US/docs/Web/API/Node/rootNode /en-US/docs/Web/API/Node/getRootNode -/en-US/docs/Web/API/NodeFilter.acceptNode /en-US/docs/Web/API/NodeFilter/acceptNode +/en-US/docs/Web/API/NodeFilter /en-US/docs/Web/API/Document/createNodeIterator +/en-US/docs/Web/API/NodeFilter.acceptNode /en-US/docs/Web/API/Document/createNodeIterator +/en-US/docs/Web/API/NodeFilter/acceptNode /en-US/docs/Web/API/Document/createNodeIterator /en-US/docs/Web/API/NodeIterator.detach /en-US/docs/Web/API/NodeIterator/detach /en-US/docs/Web/API/NodeIterator.filter /en-US/docs/Web/API/NodeIterator/filter /en-US/docs/Web/API/NodeIterator.nextNode /en-US/docs/Web/API/NodeIterator/nextNode diff --git a/files/en-us/_wikihistory.json b/files/en-us/_wikihistory.json index 4e87713b6c1ebbb..cb39583698b42aa 100644 --- a/files/en-us/_wikihistory.json +++ b/files/en-us/_wikihistory.json @@ -60850,39 +60850,6 @@ "Fguisset" ] }, - "Web/API/NodeFilter": { - "modified": "2020-10-15T21:11:18.491Z", - "contributors": [ - "lionel-rowe", - "Zearin_Galaurum", - "ExE-Boss", - "jpmedley", - "krosylight", - "JonMarkPerry", - "abbycar", - "a0preetham", - "fscholz", - "kollishivagangadhar", - "kennethcachia", - "Jesse", - "teoli", - "Sheppy", - "Brettz9", - "RobG" - ] - }, - "Web/API/NodeFilter/acceptNode": { - "modified": "2020-10-15T21:24:48.176Z", - "contributors": [ - "sideshowbarker", - "ExE-Boss", - "abbycar", - "fscholz", - "sayanchowdhury", - "teoli", - "Khodaidad_Basharmand" - ] - }, "Web/API/NodeIterator": { "modified": "2020-10-15T21:14:44.038Z", "contributors": [ diff --git a/files/en-us/web/api/document/createnodeiterator/index.md b/files/en-us/web/api/document/createnodeiterator/index.md index 3efe26e9b4bdafa..4010a847a2a5ee6 100644 --- a/files/en-us/web/api/document/createnodeiterator/index.md +++ b/files/en-us/web/api/document/createnodeiterator/index.md @@ -48,15 +48,25 @@ const nodeIterator = document.createNodeIterator(root[, whatToShow[, filter]]); | `NodeFilter.SHOW_TEXT` | `4` | Shows {{ domxref("Text") }} nodes. | - `filter` {{ optional_inline() }} - - : An object implementing the {{ domxref("NodeFilter") }} interface. Its - `acceptNode()` method will be called for each node in the subtree based at - root which is accepted as included by the whatToShow flag to determine whether or not - to include it in the list of iterable nodes (a simple callback function may also be - used instead). The method should return one of `NodeFilter.FILTER_ACCEPT`, - `NodeFilter.FILTER_REJECT`, or `NodeFilter.FILTER_SKIP`. See the - [Example](#example). - -## Example + - : A callback function or an object with an `acceptNode()` method. The function or method will be called for each node in the subtree based at root which is accepted as included by the whatToShow flag to determine whether or not to include it in the list of iterable nodes. The method should return one of `NodeFilter.FILTER_ACCEPT`, `NodeFilter.FILTER_REJECT`, or `NodeFilter.FILTER_SKIP`. See the [Example](#example). + +## Examples + +```js +const nodeIterator = document.createNodeIterator( + document.body, + NodeFilter.SHOW_ELEMENT, + (node) => node.nodeName.toLowerCase() === 'p' ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT +); +const pars = []; +let currentNode; + +while (currentNode = nodeIterator.nextNode()) { + pars.push(currentNode); +} +``` + +The same, but using an object with an `acceptNode()` method: ```js const nodeIterator = document.createNodeIterator( diff --git a/files/en-us/web/api/nodefilter/acceptnode/index.md b/files/en-us/web/api/nodefilter/acceptnode/index.md deleted file mode 100644 index e25384462076b0c..000000000000000 --- a/files/en-us/web/api/nodefilter/acceptnode/index.md +++ /dev/null @@ -1,130 +0,0 @@ ---- -title: NodeFilter.acceptNode() -slug: Web/API/NodeFilter/acceptNode -tags: - - API - - DOM - - DOM Reference - - Method - - NodeFilter -browser-compat: api.NodeFilter.acceptNode ---- -{{APIRef("DOM")}} - -The **`NodeFilter.acceptNode()`** method returns an -`unsigned short` 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 -`NodeFilter`. Possible return values are: - -
Constant | -Description | -
---|---|
NodeFilter.FILTER_ACCEPT |
- - Value returned by the - {{ domxref("NodeFilter.acceptNode()") }} method when a node - should be accepted. - | -
NodeFilter.FILTER_REJECT |
-
- - 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 |
-
NodeFilter.FILTER_SKIP |
-
- - 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". - - |
-
Constant | -Description | -
---|---|
FILTER_ACCEPT |
- - Value returned by the - {{domxref("NodeFilter.acceptNode()")}} method when a node - should be accepted. - | -
FILTER_REJECT |
-
- - 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 |
-
- - 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". - - |
-