Element.getAttributeNode

  • Revision slug: DOM/element.getAttributeNode
  • Revision title: element.getAttributeNode
  • Revision id: 71299
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment 27 words added, 2 words removed

Revision Content

{{ DomRef() }}{{ deprecated_header("7.0") }}

Summary

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

Note: This method has been deprecated; you should use {{ doxref("element.getAttribute()") }} instead.

Syntax

var 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

When called on an HTML element in a DOM flagged as an HTML document, getAttributeNode lower-cases its argument before proceeding.

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.

{{ DOMAttributeMethods() }}

Specifications

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

Revision Source

<p>{{ DomRef() }}{{ deprecated_header("7.0") }}</p>
<h3>Summary</h3>
<p>Returns the specified attribute of the specified element, as an <code>Attr</code> node.</p>
<div class="note"><strong>Note:</strong> This method has been deprecated; you should use {{ doxref("element.getAttribute()") }} instead.</div>
<h3>Syntax</h3>
<pre class="eval"><em>var attrNode</em> = <em>element</em>.getAttributeNode(<em>attrName</em>); 
</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>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>Notes</h3>
<p>When called on an HTML element in a DOM flagged as an HTML document, <code>getAttributeNode</code> lower-cases its argument before proceeding.</p>
<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/Node.parentNode" title="En/DOM/Node.parentNode">parentNode</a>, <a href="/En/DOM/Node.previousSibling" title="En/DOM/Node.previousSibling">previousSibling</a>, and <a href="/En/DOM/Node.nextSibling" title="En/DOM/Node.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" title="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>{{ DOMAttributeMethods() }}</p>
<h3>Specifications</h3>
<ul> <li><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>)</li> <li><a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#apis-in-html-documents">HTML 5: APIs in HTML documents</a></li>
</ul>
<p>{{ languages( { "fr": "fr/DOM/element.getAttributeNode", "ja": "ja/DOM/element.getAttributeNode", "pl": "pl/DOM/element.getAttributeNode" } ) }}</p>
Revert to this revision