W3cubDocs

/Web APIs

Element: getElementsByTagNameNS() method

The Element.getElementsByTagNameNS() method returns a live HTMLCollection of elements with the given tag name belonging to the given namespace. It is similar to Document.getElementsByTagNameNS, except that its search is restricted to descendants of the specified element.

Syntax

js

getElementsByTagNameNS(namespaceURI, localName)

Parameters

  • namespaceURI is the namespace URI of elements to look for (see Element.namespaceURI and Attr.namespaceURI). For example, if you need to look for XHTML elements, use the XHTML namespace URI, http://www.w3.org/1999/xhtml.
  • localName is either the local name of elements to look for or the special value "*", which matches all elements (see Element.localName and Attr.localName).

Return value

A live HTMLCollection of found elements in the order they appear in the tree.

Examples

js

// 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

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
getElementsByTagNameNS
1Initially, this method was returning a NodeList; it was then changed to reflect the spec change.
12
1["The behavior of element.getElementsByTagNameNS changed between Firefox 3.5 and Firefox 3.6. In Firefox 3.5 and before, this function would automatically case-fold any queries so that a search for \"foo\" would match \"Foo\" or \"foo\". In Firefox 3.6 and later this function is now case-sensitive so that a query for \"foo\" will only match \"foo\" and not \"Foo\". For more background on this, please see the comment from Henri Sivonen about the change. You can also look at the relevant part of the standard, which states which parts of the API are case-sensitive and which parts aren't.", "Before Firefox 19, this method was returning a NodeList; it was then changed to reflects the spec change."]
9
≤12.1Initially, this method was returning a NodeList; it was then changed to reflect the spec change.
1Initially, this method was returning a NodeList; it was then changed to reflect the spec change.
4.4Initially, this method was returning a NodeList; it was then changed to reflect the spec change.
18Initially, this method was returning a NodeList; it was then changed to reflect the spec change.
4Before Firefox 19, this method was returning a NodeList; it was then changed to reflects the spec change.
≤12.1Initially, this method was returning a NodeList; it was then changed to reflect the spec change.
1Initially, this method was returning a NodeList; it was then changed to reflect the spec change.
1.0Initially, this method was returning a NodeList; it was then changed to reflect the spec change.
all_elements_selector 1 12 1 9 ≤15 1 4.4 18 4 ≤14 1 1.0

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Element/getElementsByTagNameNS