getAttributeNode
Summary
Retrieves an attribute node by name.
Method of dom/Elementdom/Element
Syntax
var attributeNode = element.getAttributeNode();
Return Value
Returns an object of type DOM NodeDOM Node
An attribute node.
Examples
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>
<html>
<head>
<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>
Related specifications
- DOM Level 3 Core
- Recommendation
Attributions
Microsoft Developer Network: [Windows Internet Explorer API reference Article]