<html>
<head>
<title>NodeIterator Example</title>
<script type="text/javascript">
var iterator = null;
function makeList() {
var oDiv = document.getElementById("div1");
var oFilter = new Object;
oFilter.acceptNode = function (oNode) {
return (oNode.tagName == "P") ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT;
};
iterator = document.createTreeWalker(oDiv, NodeFilter.SHOW_ELEMENT, oFilter, false);
var oOutput = document.getElementById("text1");
var oNode = iterator.nextNode();
while (oNode) {
oOutput.value += oNode.tagName + "\n";
oNode = iterator.nextNode();
}
}
</script>
</head>
<body>
<P>A<strong>B</strong> C <code>D</code>F<code>G</code>H</p>
<div id="div1">
<P>Hello <b>World!</b></p>
<ul>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
</ul>
</div>
<textarea rows="10" cols="40" id="text1"></textarea><br />
<input type="button" value="Make List" onclick="makeList()" />
</body>
</html>
Quote from:
Professional JavaScript for Web Developers
by Nicholas C. Zakas (Author)
# Paperback: 672 pages
# Publisher: Wrox (April 22, 2005)
# Language: English
# ISBN-10: 0764579088
# ISBN-13: 978-0764579080
23.15.NodeFilter |
| 23.15.1. | Firefox only Node filter |