English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM getElementsByTagName() method

HTML DOM Element Object

getElementsByTagName()The method returns a list similar to an array, containing child elements of elements with the specified tag name.

The returned list is sorted in the order of the elements as they appear in the source code.

You can access the returned list by index number. The index starts from 0.

UsinglengthThe attribute determines the number of child elements with the specified tag name, and then you can iterate over all elements and extract the required information.

element.getElementsByTagName is similar todocument.getElementsByTagName() However, it only searches for elements that are descendants of the specified element.

Syntax:

element.getElementsByTagName(tag)
var gBox = document.getElementById("greenBox");
gBox.getElementsByTagName("P")[0].innerHTML = "Hello World!!!";
Test and See‹/›

Browser Compatibility

getElementsByTagName() method is fully supported in all browsers:

Methods
getElementsByTagName()YesYesYesYesYes

Parameter Value

ParameterDescription
tagThe tag name of the child element you want to get.

Technical Details

Return Value:Returns an array-like object of all child elements with the specified tag name
DOM Version:DOM Level1

Related References

HTML DOM Referencedocument.getElementsByTagName()Methods

HTML DOM Element Object