The href
property sets or gets the value of the href
attribute of an area.
Possible values:
Change the URL of a link in an area:
document.getElementById("myArea").href = "sun.htm";
Click the button to change the value of the href
attribute.
<!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 2 s . c om*/ <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("myArea").href = "https://www.java2s.com/index.html"; document.getElementById("demo").innerHTML = "The link now goes to index.htm."; } </script> </body> </html>