Javascript - document.getElementsByTagName() methodThe document.getElementsByTagName() method returns all the element of specified tag name. The syntax of the getElementsByTagName() method is given below: Here, name is required. Example of document.getElementsByTagName() methodIn this example, we going to count total number of paragraphs used in the document. To do this, we have called the document.getElementsByTagName("p") method that returns the total paragraphs. Output of the above exampleThis is a pragraph Here we are going to count total number of paragraphs by getElementByTagName() method. Let's see the simple example Another example of document.getElementsByTagName() methodIn this example, we going to count total number of h2 and h3 tags used in the document. Output of the above exampleThis is h2 tagThis is h2 tagThis is h3 tagThis is h3 tagThis is h3 tagNote: Output of the given examples may differ on this page because it will count the total number of para , total number of h2 and total number of h3 tags used in this document.Next TopicJavascript innerHTML |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India