Syntax
js
getElementsByTagName(tagName)
Parameters
tagName-
The qualified name to look for. The special string
"*"represents all elements. For compatibility with XHTML, lower-case should be used.
Return value
A live HTMLCollection of elements with a matching tag name, in the order they appear. If no elements are found, the HTMLCollection is empty.
Examples
js
// Check the status of each data cell in a table
const table = document.getElementById("forecast-table");
const cells = table.getElementsByTagName("td");
for (const cell of cells) {
const status = cell.getAttribute("data-status");
if (status === "open") {
// Grab the data
}
}
Specifications
| Specification |
|---|
| DOM # dom-element-getelementsbytagname |