×

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 countheading(){

 var totalheading=document.getElementsByTagName("h5");

 alert("total h5 tags are: "+totalheading.length);

 }

</script>

<h5>this is a heading</h5>

<h5> we are going to count total number of heading by getElementByTagName<h5>

<h5>simple example of getElementByTagName</h5>

<h5>My name is parveen</h5>

<button onclick="countheading()">count heading</button>

</body>

</html>


Output

this is a paragraph

we are going to count total number of paragraphs by getElementByTagName

simple example of getElementByTagName

My name is parveen









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