Javascript DOM HTML Area target Property set

Introduction

The target property sets or gets the target attribute of an area.

The target attribute specifies where to open the linked document.

Its possible values are listed in the following table:

Value Description
_blankOpen the link in a new window
_self Open the link in the same frame as it was clicked. Default.
_parent Open the link in the parent frameset
_top Open the link in the full body of the window
framename Open the link in a named frame

Change the target for a specific area in an image-map:

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

Click the button to set the value of the target attribute for the myArea area in the image-map to "_blank".

View in separate window

<!DOCTYPE html>
<html>
<body>

<img src="image1.png" width="100" height="100" usemap="#myFlagMap">

<map name="myFlagMap">
  <area id="myArea" 
        shape="circle" 
        coords="50,50,40" 
        alt="Target" 
        href="https://www.java2s.com">
</map>/* w w  w .  j a v  a  2s. com*/

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

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

<script>
function myFunction() {
  document.getElementById("myArea").target = "_blank";
  document.getElementById("demo").innerHTML = "The value of the target attribute was changed.";
}
</script>

</body>
</html>



PreviousNext

Related