La méthode Element.getElementsByTagNameNS() renvoie un objet HTMLCollection avec le nom de balise donné appartenant à l'espace de noms donné. Il est similaire à  Document.getElementsByTagNameNS, à part que sa recherche est restreinte aux descendants de l'élément spécifié.

Syntaxe

elements =element.getElementsByTagNameNS(namespaceURI,localName) 
  • elements est une  HTMLCollection des éléments trouvés dans leur ordre d'apparition dans l'arbre.
  • element est l'élément depuis lequel la recherche doit débuter. Notez que seuls les descendants de cet élément font partie de la recherche, pas le nœud lui-même.
  • namespaceURI est l'URI d'espace de noms des éléments à rechercher (voir namespaceURI). Par exemple, si vous cherchez des éléments XHTML, utilisez l'URI d'espace de noms XHTML, http://www.w3.org/1999/xhtml.
  • localName est soit le nom local des éléments à rechercher, soit la valeur spéciale "*", qui correspond à tous les éléments (voir Node.localName ).

Exemple

// vérifie l'alignement d'une série de cellules d'un tableau dans un document XHTML. 
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") { 
        // saisit les données 
    }
}

Spécifications

Spécification État Commentaires
DOM
La définition de 'Element.getElementsByTagNameNS()' dans cette spécification.
Standard évolutif Modification du type de la valeur de retour : passage de NodeList à HTMLCollection.
Document Object Model (DOM) Level 3 Core Specification
La définition de 'Element.getElementsByTagNameNS()' dans cette spécification.
Obsolete Aucune modification depuis Document Object Model (DOM) Level 2 Core Specification.
Document Object Model (DOM) Level 2 Core Specification
La définition de 'Element.getElementsByTagNameNS()' dans cette spécification.
Obsolete Définition initiale.

Compatibilité des navigateurs

Update compatibility data on GitHub
OrdinateurMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariWebview AndroidChrome pour AndroidFirefox pour AndroidOpera pour AndroidSafari sur iOSSamsung Internet
getElementsByTagNameNSChrome Support complet 1
Notes
Support complet 1
Notes
Notes Initially, this method was returning a NodeList; it was then changed to reflect the spec change.
Edge Support complet 12Firefox Support complet Oui
Notes
Support complet Oui
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 Support complet 5.5Opera Support complet Oui
Notes
Support complet Oui
Notes
Notes Initially, this method was returning a NodeList; it was then changed to reflect the spec change.
Safari Support complet 6
Notes
Support complet 6
Notes
Notes Initially, this method was returning a NodeList; it was then changed to reflect the spec change.
WebView Android Support complet OuiChrome Android Support complet OuiFirefox Android Support complet Oui
Notes
Support complet Oui
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 Support complet OuiSafari iOS Support complet OuiSamsung Internet Android Support complet Oui
getElementsByTagNameNS(*)Chrome Support complet 1Edge Support complet OuiFirefox Support complet OuiIE Support complet 6Opera Support complet OuiSafari Support complet OuiWebView Android Support complet OuiChrome Android Support complet 18Firefox Android Support complet Oui
Notes
Support complet Oui
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 Support complet OuiSafari iOS Support complet OuiSamsung Internet Android Support complet Oui

Légende

Support complet  
Support complet
Voir les notes d'implémentation.
Voir les notes d'implémentation.

Étiquettes et contributeurs liés au document

Étiquettes : 
Dernière mise à jour par : wbamberg,