Learn HTML DOM
Accessing DOM Elements
3.2
Lesson

Selecting DOM Elements Using Tag Name

To select a group of elements, we need to target either the tag names or the class names.

getElementsByTagName will select all the HTML elements which match the provided tag name.

The method returns an array-like list of elements. So, we can access a specific element using the bracket notation, []. But none of the array methods will work though.

In the above example, we get the list of p elements, and then we loop over them to apply changes to each one of them.

If you want to use the array methods, you can convert the list to an array using the Array.from() method.