HTML DOM getElementsByTagName() method
Example
Change the text of the first list item in the list:
var list=document.getElementsByTagName("UL")[0]
list.getElementsByTagName("LI")[0].innerHTML="Milk";
Before modifying the text:
- Coffee
- Tea
After modifying the text:
- Milk
- Tea
Try it »
Definition and Usage
The getElementsByTagName() method returns a collection of objects with the specified tag name.
**Tip:** If you pass the special string "*" to the getElementsByTagName() method, it will return a list of all elements in the document, arranged in the same order as they appear in the document.
Browser support





All major browsers support the getElementsByTagName() method
Syntax
element
.getElementsByTagName(
tagname
)
Parameters
| Parameters | Type | Description |
|---|---|---|
| tagname | String | Required. The tag name of the child element you want to get. |
Return Value
| Type | Description |
|---|---|
| NodeList object | The returned elements are in the same order as they appear in the document. |
Technical Details
| DOM version | Core Level 1 Element Object |
|---|
Element object