Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM getElementsByTagName() method

HTML DOM getElementsByTagName() method

Element Object Reference Element object

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:

After modifying the text:

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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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 Reference Element object