×

Html & Html5

it training classes Logo

The World's best Software Development Study Portal

Js getElementsByTagName



The getElementsByTagName method of Document interface returns an HTMLCollection of elements with the given tag name.The getElementsByTagName method of Document interface returns an HTMLCollection of elements with the given tag name.

we are going to count total number of paragraphs by getElementByTagName.

<html>

<body>

<script>

       function countparagraph(){

 var totalparagraph=document.getElementsByTagName("p");

 alert("total p tags are: "+totalparagraph.length);

 }

</script>

<p>this is a paragraph</p>

<p> we are going to count total number of paragraphs by getElementByTagName</p>

<p>simple example of getElementByTagName</p>

<p>My name is parveen</p>

<button onclick="countparagraph()">count paragraph</button>

</body>

</html>








JS training insitute | Best IT Training classes in Gurgaon | Web Designing Training Institute