Javascript DOM HTML Area pathname Property set

Introduction

The pathname property sets or gets the path name of the href attribute value.

Change the path name of the URL for a specific area in an image-map:

document.getElementById("myArea").pathname = "somenewpathname";

Click the button to change the path name of the href attribute for the myArea area in the image-map.

View in separate window

<!DOCTYPE html>
<html>
<body>

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

<map name="myFlagMap">
  <area id="myArea" 
        target="_blank" 
        shape="circle" 
        coords="50,50,40" 
        alt="Target" 
        href="http://www.example.com/test.htm">
</map>//ww w  . j a  v  a 2  s.  c om
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  document.getElementById("myArea").pathname = "newValue";
  document.getElementById("demo").innerHTML = "The pathname was changed";
}
</script>

</body>
</html>



PreviousNext

Related