The getAttributeNode()
method returns the attribute
with the specified name, as an Attr object.
getAttributeNode |
Yes | Yes | Yes | Yes | Yes |
element.getAttributeNode(attributename)
Parameter | Type | Description |
---|---|---|
attributename | String | Required. The name of the attribute |
It return a Attr object type value.
The following code shows how to get the target attribute of a link.
<!DOCTYPE html>
<html>
<body>
a href="http://example" target="_blank">test</a>.
<p id="demo">test</p>
<button onclick="myFunction()">test</button>
<!-- www . j a v a 2 s. c om-->
<script>
function myFunction()
{
var a=document.getElementsByTagName("a")[0];
var x=document.getElementById("demo");
x.innerHTML=a.getAttributeNode("target").value;
}
</script>
</body>
</html>
The code above is rendered as follows: