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.

Thuộc tính Element.getElementsByTagNameNS() method trả về 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.

Cú pháp

js
getElementsByTagNameNS(namespaceURI, localName)

Tham số

namespaceURI

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

Either the local name of elements to look for or the special value "*", which matches all elements (see Element.localName and Attr.localName).

Giá trị trả về

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

Ví dụ

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

Đặc tả kỹ thuật

Specification
DOM
# dom-element-getelementsbytagnamens

Trình duyệt hỗ trợ