topical media & game development
professional-javascript-06-TreeWalkerExample2.htm / htm
<html>
<head>
<title>TreeWalker Example</title>
<script type="text/javascript">
var walker = null;
function makeList() {
var oDiv = document.getElementById("div1");
walker = document.createTreeWalker(oDiv, NodeFilter.SHOW_ELEMENT, null, false);
var oOutput = document.getElementById("text1");
walker.firstChild(); //go to <p>
walker.nextSibling(); //go to <ul>
oNode = walker.firstChild(); //go to <li>
while (oNode) {
oOutput.value += oNode.tagName + "\n";
oNode = walker.nextSibling();
}
}
</script>
</head>
<body>
<p><strong>Note:</strong> The <code>TreeWalker</code> object has only been implemented in Opera (version 7.6 and higher), Safari (version 1.3 and higher), and Firefox (version 1.0 and higher). It has not been implemented in Internet Explorer (so this example won't work).</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>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.