Get first child from TreeWalker (Firefox only) : TreeWalker « DOM Node « JavaScript Tutorial






<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");

       oNode = walker.firstChild();
       while (oNode) {
           oOutput.value += oNode.tagName + "\n";
           oNode = walker.nextSibling();
       }

   }

</script>
</head>
<body>
<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>








23.22.TreeWalker
23.22.1.Get first child from TreeWalker (Firefox only)
23.22.2.Get last child from TreeWalker