JavaScript get element by tag Method | Simple Example code

Use getElementsByTagName() method to get the element by tag in JavaScript. Tag name are in HTML h1, p, div, etc.

The Element.getElementsByTagName() method returns a live HTMLCollection of elements with the given tag name.

Example of JavaScript get element by tag

Here is HTML example code to get all elements in the document with the specified “h4” tag name:

Output:

JavaScript get element by tag Method

Do comment if you have another example or doubts or suggestions on this topic.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.