I volontari di MDN non hanno ancora tradotto questo articolo in Italiano. Unisciti a noi e traducilo tu stesso.
Puoi anche consultare l’articolo in English (US).

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)
  • elements is a live HTMLCollection of found elements in the order they appear in the tree.
  • element is 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.
  • 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).

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
DOM
The definition of 'Element.getElementsByTagNameNS()' in that specification.
Living Standard Changed the return value from NodeList to HTMLCollection.
Document Object Model (DOM) Level 3 Core Specification
The 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 Specification
The definition of 'Element.getElementsByTagNameNS()' in that specification.
Obsolete Initial definition

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 1
Notes
Full support 1
Notes
Notes Initially, this method was returning a NodeList; it was then changed to reflect the spec change.
Edge Full support YesFirefox Full support Yes
Notes
Full support Yes
Notes
Notes 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.
Notes Prior to Firefox 19, this method was returning a NodeList; it was then changed to reflects the spec change.
IE Full support 5.5Opera Full support Yes
Notes
Full support Yes
Notes
Notes Initially, this method was returning a NodeList; it was then changed to reflect the spec change.
Safari Full support Yes
Notes
Full support Yes
Notes
Notes Initially, this method was returning a NodeList; it was then changed to reflect the spec change.
WebView Android Full support YesChrome Android ? Edge Mobile Full support YesFirefox Android Full support Yes
Notes
Full support Yes
Notes
Notes 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.
Notes Prior to Firefox 19, this method was returning a NodeList; it was then changed to reflects the spec change.
Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?
getElementsByTagName(*)Chrome Full support 1Edge Full support YesFirefox Full support YesIE Full support 6Opera Full support YesSafari Full support YesWebView Android ? Chrome Android ? Edge Mobile ? Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.

Tag del documento e collaboratori

Ultima modifica di: BloodyMettle,