

We will use getElementsByTagName() function to count the number of link elements available in the document by specifying “a” tag name in this function. From this return array the total number of “li” elements is printing as in above code. Once we click on the “Count Fruits” button the output is:Īs in the above code or document the list of elements (fruits) are created and the button is created to count the list of fruits available, once we click this button it called to the countFun() function inside where it called todocument.getElementsByTagName(“li”) function which return the array of all “li” elements. Var n = document.getElementsByTagName("li") Īlert("The total number of fruits are : "+n.length) Here we are going to count total number of fruits by getElementByTagName() function. This is an example for getElementsByTagName() function We will use getElementsByTagName() function to count the number of list elements available in the document by specifying “li” tag name in this function.

Given below are the examples are mentioned: Example #1 Examples of JavaScript getElementsByTagName()
