Javascript DOM HTML Anchor target Property set

Introduction

Change the target of a link to "_blank".

The link will be opened in a new window.

document.getElementById("myAnchor").target = "_blank";

Click the button to set the value of the target attribute of the link to "_blank".

View in separate window

<!DOCTYPE html>
<html>
<body>
<p><a id="myAnchor" href="https://www.java2s.com">Examples</a></p>
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {//  w  w  w .jav  a 2s  .  c  o  m
  document.getElementById("myAnchor").target = "_blank";
  document.getElementById("demo").innerHTML = "The value of the target attribute was set.";
}
</script>
</body>
</html>



PreviousNext

Related