Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <body> <h1>The NodeList Object</h1> <h2>The item() or [] Method</h2> <!-- This is a comment node! --> <p>The node names of the body element's child nodes are:</p> <p id="demo"></p> <p>Note: Whitespace between elements are text nodes.</p> <script> const list = document.body.childNodes; let text = ""; for (let i = 0; i < list.length; i++) { text += list[i].nodeName + "<br>"; } document.getElementById("demo").innerHTML = text; </script> </body> </html>