In JavaScript, the getElementsByTagName() method returns a liveHTMLCollection of every descendant with the given tag name (MDN). The element you call it on is not included — only its descendants.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call el.getElementsByTagName. Start with this line.
JavaScript
el.getElementsByTagName(tagName)
Call
What it does
el.getElementsByTagName(tagName)
Primary signature.
el.getElementsByTagName(...)
Call with the arguments your case needs.
Built into the browser. Call getElementsByTagName(...) on an Element — no import required.
Library declarations
JavaScript
el.getElementsByTagName(tagName)
Parameters
This member has no parameters beyond those shown in the signature.
Return Value
Return Value
Description
*
Live HTMLCollection
JavaScript Examples
Example 1 — Table Cells (MDN)
Collect every td under a table and read a data attribute.
JavaScript
const table = document.getElementById("forecast-table");
const cells = table.getElementsByTagName("td");
for (const cell of cells) {
console.log(cell.getAttribute("data-status"));
}
Capture the collection once. No need to call the method again.
Mutate the DOM. Append a new <li>.
Length updates automatically. That is what “live” means (MDN).
Contrast with querySelectorAll. A NodeList snapshot would stay at the old length.
Compatibility
Browser Support
Element.getElementsByTagName() is Baseline Widely available (MDN: across browsers since July 2015). Safe to use in modern evergreen browsers.
✓ Baseline · Widely available
getElementsByTagName()
Live HTMLCollection of descendant elements matching a tag name (or *).
99%Widely available
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
getElementsByTagName()Excellent
Bottom line: Use for fast tag lookups in a subtree; use getElementsByTagNameNS for SVG/XML namespaces, and querySelectorAll for CSS selectors or static lists.
Frequently Asked Questions
It returns a live HTMLCollection of descendant elements with the given tag name. The search is limited to the subtree of the element you call it on — not the element itself (MDN).
No. MDN marks Element.getElementsByTagName() as Baseline Widely available (across browsers since July 2015). It is not Deprecated, Experimental, or Non-standard.
A string with the qualified tag name to look for. The special string "*" returns all descendant elements. In HTML documents, the argument is lower-cased before searching (MDN).
getElementsByTagName() returns a live HTMLCollection that updates when the DOM changes. querySelectorAll() returns a static NodeList snapshot.
Yes. MDN: the list updates automatically with the DOM tree, so you do not need to call the method again after DOM changes.
In HTML documents, getElementsByTagName lower-cases the argument, which is undesirable for camel-cased SVG tags. Use getElementsByTagNameNS() to preserve capitalization (MDN).