Dom CORE : Objet Element.getAttributeNode

La méthode javascript getAttributeNode

Définition

La méthode javascript getAttributeNode(nom) de l'objet Element permet de récupérer un objet attribut (voir Objet Attribut) d'un élément par rapport à son nom dans un élement.
Exemple de code :
<ol id="getAttributeNode">
  <li lang="fr">getAttributeNode 1</li>
  <li lang="be">getAttributeNode 2</li>
  <li lang="br">getAttributeNode 3</li>
  <li lang="el">getAttributeNode 4</li>
</ol>

var GetAttributeNode= document.getElementsByTagName("li");
for(var i=0; i< GetAttributeNode.length; i++){
  var AttributeNode = GetAttributeNode.item(i).getAttributeNode("lang")
  alert(AttributeNode.value);
}
//fr, be, br, el

Paramètres de getAttributeNode

Paramètre

La méthode javascript getAttributeNode(nom) de l'objet Element accepte comme paramètres :
- nom valeur de type string. Elle correspond au nom de l'attribut à récupérer.

Valeurs retournées de getAttributeNode

Valeur retournée

La méthode javascript getAttributeNode(nom) de l'objet Element renvoie :
- un objet Attribut (voir Objet Attribut).
- "null" si l'attribut n'existe pas.

Exceptions de getAttributeNode

Exception

La méthode javascript getAttributeNode() de l'objet Element renvoie aucune exception.

Exemples de getAttributeNode

Exemple

Voici le document XML suivant :
Exemple de code :
<ol id="identifiant">
  <li></li>
  <li></li>
</ol>

Code javascript :
Exemple de code :
var objet = document.getElementsByTagName("ol");
var AttributeNode = objet.getAttributeNode("id");
alert(AttributeNode.name +"=" +AttributeNode.value);

Tester getAttributeNode("id")