Element.getAttributeNode

  • Revision slug: DOM/element.getAttributeNode
  • Revision title: element.getAttributeNode
  • Revision id: 71294
  • Created:
  • Creator: Celelibi
  • Is current revision? No
  • Comment add language link

Revision Content

{{template.DomRef()}}

Summary

Returns the specified attribute of the specified element, as an Attr node.

Syntax

attrNode = element.getAttributeNode(attrName) 
  • attrNode is an Attr node for the attribute.
  • attrName is a string containing the name of the attribute.

Example

// html: <div id="top" /> 
var t = document.getElementById("top"); 
var idAttr = t.getAttributeNode("id"); 
alert(idAttr.value == "top")

Notes

The Attr node inherits from Node, but is not considered a part of the document tree. Common Node attributes like parentNode, previousSibling, and nextSibling are null for an Attr node. You can, however, get the element to which the attribute belongs with the ownerElement property.

getAttribute is usually used instead of getAttributeNode to get the value of an element's attribute.

{{template.DOMAttributeMethods()}}

Specification

DOM Level 2 Core: getAttributeNode (introduced in DOM Level 1 Core)

{{ wiki.languages( { "fr": "fr/DOM/element.getAttributeNode", "pl": "pl/DOM/element.getAttributeNode" } ) }}

Revision Source

<p>
{{template.DomRef()}}
</p>
<h3 name="Summary"> Summary </h3>
<p>Returns the specified attribute of the specified element, as an <code>Attr</code> node.
</p>
<h3 name="Syntax"> Syntax </h3>
<pre class="eval"><i>attrNode</i> = <i>element</i>.getAttributeNode(<i>attrName</i>) 
</pre>
<ul><li> <code>attrNode</code> is an <code>Attr</code> node for the attribute.
</li><li> <code>attrName</code> is a string containing the name of the attribute.
</li></ul>
<h3 name="Example"> Example </h3>
<pre>// html: &lt;div id="top" /&gt; 
var t = document.getElementById("top"); 
var idAttr = t.getAttributeNode("id"); 
alert(idAttr.value == "top")

</pre>
<h3 name="Notes"> Notes </h3>
<p>The <code>Attr</code> node inherits from <code>Node</code>, but is not considered a part of the document tree. Common <code>Node</code> attributes like <a href="en/DOM/element.parentNode">parentNode</a>, <a href="en/DOM/element.previousSibling">previousSibling</a>, and <a href="en/DOM/element.nextSibling">nextSibling</a> are <code>null</code> for an <code>Attr</code> node. You can, however, get the element to which the attribute belongs with the <code>ownerElement</code> property.
</p><p><a href="en/DOM/element.getAttribute">getAttribute</a> is usually used instead of <code>getAttributeNode</code> to get the value of an element's attribute.
</p><p>{{template.DOMAttributeMethods()}}
</p>
<h3 name="Specification"> Specification </h3>
<p><a class="external" href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-217A91B8">DOM Level 2 Core: getAttributeNode</a> (introduced in <a class="external" href="http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#method-getAttributeNode">DOM Level 1 Core</a>)
</p>{{ wiki.languages( { "fr": "fr/DOM/element.getAttributeNode", "pl": "pl/DOM/element.getAttributeNode" } ) }}
Revert to this revision