HTML DOM getElementsByTagName()Method

元素对象参考手册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:

  • Coffee
  • Tea

After modifying the text:

  • Milk
  • Tea

Try it Yourself »

Definition and Usage

The getElementsByTagName() method returns a collection of objects with the specified tag name.

Tip:If the special string "*" is passed to the getElementsByTagName() method, it will return a list of all elements in the document, and the order of the elements is the order in which they appear in the document.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the getElementsByTagName() method


Syntax

element.getElementsByTagName(tagname)

Parameters

Parameter Type Description
tagname String Required. The tag name of the elements you want to get.

Return Value

Type Description
NodeList object The returned elements are in the order in which they appear in the document.

Technical Details

DOM Version Core Level 1 Element Object


元素对象参考手册Element Object

Other Extensions