Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining

getAttributeNode method

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

Document Object Model (DOM) Level 3 Core Specification, Section 1.4



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


bstrname [in]

Type: BSTR

BSTR that specifies the IHTMLDOMAttribute2::name property of the requested IHTMLDOMAttribute2 interface.
ppAttribute [out, retval]

Type: IHTMLDOMAttribute

Address of a pointer variable that receives an IHTMLDOMAttribute2 pointer.

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, IHTMLElement6::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.

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


The following example uses IHTMLElement6::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 IHTMLElement6::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="http://msdn.microsoft.com/">
    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>



Community Additions

© 2015 Microsoft