Latest web development tutorials

HTML DOM getElementsByTagName () method

Elements Object Reference Element object

Examples

Change the text list first list item:

var list=document.getElementsByTagName("UL")[0]
list.getElementsByTagName("LI")[0].innerHTML="Milk";

Modify the text before:

  • Coffee
  • Tea

After modifying the text:

  • Milk
  • Tea

try it"

Definition and Usage

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

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


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support getElementsByTagName () method


grammar

element .getElementsByTagName( tagname )

parameter

参数 类型 描述
tagname String 必须。你想获取自元素的标签名。

return value

类型 描述
NodeList object 返回元素的顺序是它们在文档中的顺序。

technical details

DOM version Core Level 1 Element Object


Elements Object Reference Element object