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
elements = element.getElementsByTagNameNS(namespaceURI, localName)
elementsis a liveHTMLCollectionof found elements in the order they appear in the tree.elementis the element from where the search should start. Note that only the descendants of this element are included in the search, not the node itself.namespaceURIis the namespace URI of elements to look for (seeElement.namespaceURIandAttr.namespaceURI). For example, if you need to look for XHTML elements, use the XHTML namespace URI,http://www.w3.org/1999/xhtml.localNameis either the local name of elements to look for or the special value"*", which matches all elements (seeElement.localNameandAttr.localName).
Example
// check the alignment on a number of cells in a table in an XHTML document.
var table = document.getElementById("forecast-table");
var cells = table.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "td");
for (var i = 0; i < cells.length; i++) {
var axis = cells[i].getAttribute("axis");
if (axis == "year") {
// grab the data
}
}
Specifications
| Specification | Status | Comment |
| DOMThe definition of 'Element.getElementsByTagNameNS()' in that specification. | Living Standard | Changed the return value from NodeList to HTMLCollection.
|
| Document Object Model (DOM) Level 3 Core SpecificationThe definition of 'Element.getElementsByTagNameNS()' in that specification. | Obsolete | No change from Document Object Model (DOM) Level 2 Core Specification. |
| Document Object Model (DOM) Level 2 Core SpecificationThe definition of 'Element.getElementsByTagNameNS()' in that specification. | Obsolete | Initial definition |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
getElementsByTagNameNS
|
Chrome Full support 1 Full support 1 Notes' Initially, this method was returning a |
Edge
Full support 12 |
Firefox Full support Yes Full support Yes Notes' The behavior of |
IE
Full support 5.5 |
Opera Full support Yes Full support Yes Notes' Initially, this method was returning a |
Safari Full support 6 Full support 6 Notes' Initially, this method was returning a |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android Full support Yes Full support Yes Notes' The behavior of |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
| getElementsByTagNameNS(*) | Chrome
Full support 1 |
Edge
Full support 12 |
Firefox
Full support Yes |
IE
Full support 6 |
Opera
Full support Yes |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support 18 |
Firefox Android Full support Yes Full support Yes Notes' The behavior of |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support 1.0 |
Legend
- Full support
- Full support
- See implementation notes.'
- See implementation notes.
Element.getElementsByTagNameNS() by Mozilla Contributors is licensed under CC-BY-SA 2.5.