This page is Almost Ready

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.



Retrieves an attribute node by name.

Method of dom/Elementdom/Element


var attributeNode = element.getAttributeNode();

Return Value

Returns an object of type DOM NodeDOM Node

An attribute node.


The following example uses getAttributeNode to create an attribute and populate its div element. Note how the call to setAttribute changes the href value for the content attribute but not for the DOM attribute.

<!doctype html>
  <title>Attribute Node Example</title>
  <base href="">
function GetAttrNode() {
  //Retrieve an attribute node and a DOM attribute.
  var o = document.getElementById("msdn");
  var sDomAttr = o.href;

  o.setAttribute('href', 'en-us/ie/default.aspx');
  var sContentAttr = o.getAttributeNode("href");
  var sOutput = ("Content attribute node value: " + sContentAttr.value +
              "<br/>DOM attribute value: " + sDomAttr);

  document.getElementById("output").innerHTML = sOutput;
   <a id="msdn" href="en-us/default.aspx">Microsoft Developer Network</a>
   <div id="output" onmouseover="GetAttrNode()">Point here to display attribute values.</div>

Related specifications

DOM Level 3 Core