The hash
property sets or gets the anchor part of the href attribute value.
The URL anchor is after the hash sign #
.
To set the anchor, do not include the hash sign (#).
Change the anchor part of a specific area in an image-map:
document.getElementById("myArea").hash = "newhashvalue";
Click the button to change the anchor part of the href attribute for the myArea
area in the image-map.
<!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/index.html#description"> </map>//from ww w. ja v a 2s .com <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("myArea").hash = "newhashvalue"; document.getElementById("demo").innerHTML = "The anchor part was changed."; } </script> </body> </html>