Javascript examples for DOM:Element childNodes
Element childNodes Property - Find out how many child nodes a <div> element has:
<!DOCTYPE html> <html> <head> <style> div {/*from w w w.ja v a2s . c om*/ border: 1px solid black; margin: 5px; } </style> </head> <body> <button onclick="myFunction()">Test</button> <div id="myDIV"> <p>First p element (index 1)</p> <p>Second p element (index 3)</p> </div> <p id="demo"></p> <script> function myFunction() { var c = document.getElementById("myDIV").childNodes.length; document.getElementById("demo").innerHTML = c; } </script> </body> </html>