Gets the currently applied NodeFilter to the traversal.
Property of dom/NodeIteratordom/NodeIterator
SyntaxNote: This property is read-only.
var nodeFilter = nodeIterator.filter;
Return Value
Returns an object of type DOM NodeDOM Node
The NodeFilter that was applied while traversing.
ExamplesThe following example searches for table and anchor tags and reports the value of the id attribute. Although the TreeWalker preserves the hierarchical relationship of nodes, you don’t need to write recursive functions to walk the nodes in a hierarchy. The NodeFilter function skips nodes rather than rejecting them, which allows the function to examine all child nodes in the hierarchy.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function filter(node)
{
if (node.tagName == "TABLE" || node.tagName == "A")
return NodeFilter.FILTER_ACCEPT;
return NodeFilter.FILTER_SKIP;
}
function findNodes()
{
var tw = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT, filter, false);
var node, results = '';
while (node = tw.nextNode()) {
results += node.id + "<br/>";
}
document.getElementById("results").innerHTML += results;
}
function refresh()
{
window.location.reload( false );
}
</script>
</head>
<body>
<table border="1" id="myTable">
<tbody>
<tr/>
<tr>
<td><a href="" id="myLink">Text inside anchor</a></td>
</tr>
</tbody>
</table>
<div id="results">Results:<br/></div>
<button onclick="findNodes()">Find Nodes</button>
<button onclick="refresh()">Reload</button>
</body>
</html>
Usage
Use the filter property to exclude/include Nodes from the Iteration.
Notes
function myFilter(node) {
// NodeFilter function that returns one of the following flags:
// NodeFilter.FILTER_ACCEPT, NodeFilter.FILTER_REJECT, NodeFilter.FILTER_SKIP
}
Related specifications
Mozilla Developer Network : [NodeIterator.filter Article]
Microsoft Developer Network: [filter Property Article]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4