Javascript examples for DOM:Element NodeList
The length property returns the number of nodes in a NodeList object.
This property is read-only.
A Number, representing the number of nodes in the nodelist
The following code shows how to check how many <p> elements there are in the document:
<!DOCTYPE html> <html> <body> <p>The first p element in the document.</p> <p>Another p element.</p> <button onclick="myFunction()">Test</button> <p id="demo">I am also a p element.</p> <script> function myFunction() {/*from ww w. ja v a 2s. co m*/ var nodelist = document.getElementsByTagName("P").length; document.getElementById("demo").innerHTML = nodelist; } </script> </body> </html>