English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
element.getElementsByTagName(tag)
var gBox = document.getElementById("greenBox"); gBox.getElementsByTagName("P")[0].innerHTML = "Hello World!!!";Test and See‹/›
getElementsByTagName() method is fully supported in all browsers:
Methods | |||||
getElementsByTagName() | Yes | Yes | Yes | Yes | Yes |
Parameter | Description |
---|---|
tag | The tag name of the child element you want to get. |
Return Value: | Returns an array-like object of all child elements with the specified tag name |
---|---|
DOM Version: | DOM Level1 |
HTML DOM Referencedocument.getElementsByTagName()Methods