Javascript DOM HTML Area host Property set

Introduction

The host property sets or gets the host name and port part of the href attribute value.

Change the hostname and port number of the URL for a specific area in an image-map:

document.getElementById("myArea").host = "www.example.com:1234";

Click the button to change the hostname and port number of the href attribute value 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="https://www.java2s.com">
</map>//ww  w .  j av  a  2 s  . co m
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  document.getElementById("myArea").host = "www.example.com:1234";
  document.getElementById("demo").innerHTML = "The host name and port was changed.";
}
</script>

</body>
</html>



PreviousNext

Related