Javascript DOM HTML Element getAttribute() Method get anchor target attribute

Introduction

Get the value of the target attribute of an <a> element:

var x = document.getElementById("myAnchor").getAttribute("target");

Click the button to display the value of the target attribute of the link above.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {/* w  w w .  ja v a2 s. c  o  m*/
  var x = document.getElementById("myAnchor").getAttribute("target");
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related