Javascript examples for DOM:Element NodeList
Element NodeList Property - Loop through the child nodes of <body> and output the node name of each child node:
<!DOCTYPE html> <html> <body><!-- This is a comment node! --> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {// w w w .j a v a 2 s .co m var nodelist = document.body.childNodes; var txt = ""; var i; for (i = 0; i < nodelist.length; i++) { txt = txt + nodelist[i].nodeName + "<br>"; } document.getElementById("demo").innerHTML = txt; } </script> </body> </html>