Javascript examples for DOM HTML Element:Anchor
The target property sets or gets the value of the target attribute of a link.
The target attribute sets where to open the linked document.
Set the target property with the following Property Values
Value | Description |
---|---|
_blank | Opens the linked document in a new window |
_self | Opens the linked document in the same frame as it was clicked (this is default) |
_parent | Opens the linked document in the parent frameset |
_top | Opens the linked document in the full body of the window |
framename | Opens the linked document in a named frame |
A String, representing where to open the linked document
The following code shows how to Change the target of a link to "_blank" and the link will be opened in a new window:
<!DOCTYPE html> <html> <body> <p><a id="myAnchor" href="https://www.java2s.com">java2s.com</a></p> <button onclick="myFunction()">set the value of the target attribute of the link above to "_blank"</button> <p id="demo"></p> <script> function myFunction() {//from ww w . j a v a 2 s . c o m document.getElementById("myAnchor").target = "_blank"; document.getElementById("demo").innerHTML = "The value of the target attribute was set."; } </script> </body> </html>