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

Introduction

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

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

View in separate window

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

<p id="demo"></p>

<script>
function myFunction() {/*from www  .  j  a v a2  s. co  m*/
  var elmnt = document.getElementById("myAnchor");
  var attr = elmnt.getAttributeNode("target").value;
  document.getElementById("demo").innerHTML = attr;
}
</script>

</body>
</html>



PreviousNext

Related