Javascript DOM HTML Area hash Property get

Introduction

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 (#).

Return the anchor part of the URL for a specific area in an image-map:

var x = document.getElementById("myArea").hash;

Click the button to display the anchor 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" 
        shape="circle" 
        coords="50,50,40" 
        alt="Target" 
        href="https://www.java2s.com/index.html#abc">
</map>//from w  w w  .j  a  v a  2s .c o m

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

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

<script>
function myFunction() {
  var x = document.getElementById("myArea").hash;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related