Name
Document.getElementsByTagName( ) — return all Element nodes with the specified name
Availability
DOM Level 1 Core
Synopsis
Node[] getElementsByTagName(String tagname
);
Arguments
-
tagname
The tag name of the Element nodes to be returned, or the wildcard string “*” to return all Element nodes in the document regardless of tag name. For HTML documents, tag names are compared in a case-insensitive fashion.
Returns
A read-only array (technically, a NodeList) of all Element nodes in the document tree with the specified tag name. The returned Element nodes are in the same order in which they appear in the document source.
Description
This method returns a NodeList (which you can treat as a read-only array) that contains all Element nodes from the document that have the specified tag name, in the order in which they appear in the document source. The NodeList is “live”; i.e., its contents are automatically updated as necessary if elements with the specified tag name are added to or removed from the document.
HTML documents are case-insensitive, and you can specify
tagname
using any capitalization; it
matches all tags with the same name in the document, regardless of
how those tags are capitalized in the document source. XML documents,
on the other hand, are case-sensitive, and
tagname
matches only tags with the same
name and exactly the same capitalization in the document source.
Note that the Element interface defines a method by the same name that searches only a subtree of the document. ...
Get JavaScript: The Definitive Guide, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.