getAttributeNode method (Internet Explorer)

Switch View :
ScriptFree
getAttributeNode method

[This documentation is preliminary and is subject to change.]

Retrieves an attribute object referenced by the attribute.name property.

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

Syntax

object.getAttributeNode(bstrname, )

Standards information

Parameters

bstrname [in]
C++String that specifies the name property of the requested IHTMLDOMAttribute2 interface.
JavaScriptA String that specifies the name property of the requested attribute object.
ppAttribute [out, retval]
C++Address of a pointer variable that receives an IHTMLDOMAttribute2 pointer.
JavaScriptReturns a reference to an attribute object.

Return value

Type: HRESULT

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

Type: ObjectReturns a reference to an attribute object.Address of a pointer variable that receives an IHTMLDOMAttribute2 pointer.

Remarks

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

Internet Explorer 8 or later. In IE8 mode, the 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, true.

getAttributeNode was introduced in Microsoft Internet Explorer 6.

Examples

The following example uses 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 setAttribute changes the href value for the content attribute but not for the DOM attribute.


<html>
<head>
  <meta http-equiv="X-UA-Compatible" content="IE=8">
  <title>Attribute Node Example</title>
  <base href="http://msdn.microsoft.com/">
  <script>
    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;
    }
  </script>
</head>
<body>
   <a id="msdn" href="en-us/default.aspx">Microsoft Developer Network</a>
   <div id="output" onmouseover="GetAttrNode()">Point here to display attribute values.</div>
</body>
</html>

 

 

Build date: 2/14/2012