Element: getElementsByTagNameNS() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
TheElement.getElementsByTagNameNS() method returns aliveHTMLCollection of elements with the given tag name belonging to thegiven namespace. It is similar toDocument.getElementsByTagNameNS, exceptthat its search is restricted to descendants of the specified element.
In this article
Syntax
getElementsByTagNameNS(namespaceURI, localName)Parameters
namespaceURIThe namespace URI of elements to look for (see
Element.namespaceURIandAttr.namespaceURI). Forexample, if you need to look for XHTML elements, use the XHTML namespace URI,http://www.w3.org/1999/xhtml.localNameEither the local name of elements to look for or thespecial value
"*", which matches all elements (seeElement.localNameandAttr.localName).
Return value
A liveHTMLCollection of found elements in the order they appear in the tree.
Examples
// Check the alignment on a number of cells in a table in an XHTML document.const table = document.getElementById("forecast-table");const cells = table.getElementsByTagNameNS( "http://www.w3.org/1999/xhtml", "td",);for (const cell of cells) { const axis = cell.getAttribute("axis"); if (axis === "year") { // Grab the data }}Specifications
| Specification |
|---|
| DOM> # dom-element-getelementsbytagnamens> |