Javascript DOM HTML Anchor target Property get

Introduction

The target property sets or gets the value of the target attribute of a link.

The target attribute specifies where to open the linked document.

Property Values of target attribute.

Value Description
_blankOpens in a new window
_self Opens in the same window. Default
_parent Opens in the parent frameset
_top Opens in the full body of the window
framename Opens in a named frame

Return the value of the target attribute of a link:

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

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

View in separate window

<!DOCTYPE html>
<html>
<body>

<p><a id="myAnchor" target="_self" href="https://www.java2s.com/">Examples</a></p>

<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {//  ww w  . j  a v  a  2  s.  c  o m
  var x = document.getElementById("myAnchor").target;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related