HTML Editor
<!DOCTYPE html> <html lang="en-US"> <body> <div> <h1>Heading 1</h1> <p>Paragraph 1</p> <b>Bold 1</b> </div> <p>Click the button to find the number of childNodes inside div tag.</p> <button onclick="myFunction()">Click Me</button> <p id="point"></p> <script> var x = document.getElementById("point"); var y = document.getElementsByTagName("div")[0]; function myFunction(){ x.innerHTML = y.childNodes.length; } </script> <p><strong>Note</strong>: The childNodes include tags and texts.</p> </body> </html>
OUTPUT
×

Save as Private