HTML DOM getElementsByTagName()Method

Document 对象参考手册Document Object

Examples

Returns a collection of objects with the specified tag name:

document.getElementsByTagName("P");

Try it Yourself »

Definition and Usage

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

Tip:The parameter value "*" returns all elements in the document.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the getElementsByTagName() method


Syntax

document.getElementsByTagName(tagname)

Parameters

Parameters Type Description
tagname String Required. The tag name of the element you want to get.

Return Value

Type Description
NodeList object A collection of elements with the specified tag name

Technical Details

DOM Version Core Level 1 Document Object


Document 对象参考手册Document Object

Other Extensions