Javascript Reference - HTML DOM getAttributeNode() Method








The getAttributeNode() method returns the attribute with the specified name, as an Attr object.

Browser Support

getAttributeNode Yes Yes Yes Yes Yes

Syntax

element.getAttributeNode(attributename)

Parameters

Parameter Type Description
attributename String Required. The name of the attribute




Return Value

It return a Attr object type value.

Example

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: