Latest web development tutorials

HTML DOM getElementsByTagName () method

Document Object Reference Document Object

Examples

Returns a collection of objects with the specified tag name of:

document.getElementsByTagName("P");

try it"

Definition and Usage

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

Note: Parameter value "*" to return all document elements.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support getElementsByTagName () method


grammar

document.getElementsByTagName( tagname )

parameter

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

return value

类型 描述
NodeList 对象 指定标签名的元素集合

technical details

DOM version Core Level 1 Document Object


Document Object Reference Document Object