JavaScript getElementsByTagName() Method

Get Elements by Tag Name

The getElementsByTagName() method returns a collection of an elements’s child elements with the specified tag name, as a NodeList object.
Return a live HTMLCollection.


The tag_name is “div”, “span”, “p”, etc.


var list = document .getElementsByTagName(“p”); // get all p elements

list[0].style.color = “red”;
list[0].innerHTML = “Milk”;

It will change the text of the first p tag (index 0).

If you have any query or suggestions, feel free to ask me via the comment section below.

Leave a Reply