getAttributeNode method

Retrieves an IHTMLDOMAttribute2 interface referenced by the IHTMLDOMAttribute2::name property.


HRESULT retVal = object.getAttributeNode(bstrname, ppAttribute);


Return value


If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Standards information


Windows Internet Explorer 8 or later. In IE8 Standards mode, IHTMLElement4::getAttributeNode correctly populates the IHTMLDOMAttribute2::value property of the returned attribute object regardless of whether the IHTMLDOMAttribute::specified property is set to VARIANT_TRUE or VARIANT_FALSE. For more information on IE8 mode, see Defining Document Compatibility.

Internet Explorer 8 or later. In IE8 mode, the IHTMLDOMAttribute2::value property is correctly reported as a canonical attribute name. For example, <input type="text" readonly> and <input type="text" readonly="readonly"> would both set the input text field to read-only. In IE8 mode, the value is evaluated as a canonical value, "readonly". In IE7 and earlier modes, it is evaluated as a Boolean value, VARIANT_TRUE.

IHTMLElement4::getAttributeNode was introduced in Microsoft Internet Explorer 6.


The following example uses IHTMLElement4::getAttributeNode to create an attribute object and populate its value property, which is then passed by reference to an output variable for assignment to the contents of a div element. Note how the call to IHTMLElement::setAttribute changes the IHTMLLinkElement4::href value for the content attribute but not for the DOM attribute.

  <meta http-equiv="X-UA-Compatible" content="IE=8">
  <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>