Write the number of <p> elements in the document:
var x = document.getElementsByTagName("P"); document.write(x.length);
<!DOCTYPE html> <html> <body> <p>Use the getElementsByTagName() method to return an HTMLCollection.</p> <p>The number of P elements on this page:</p> <script> var x = document.getElementsByTagName("P"); document.write(x.length);// w w w . jav a 2 s . co m </script> </body> </html>