The hash
property sets or gets the anchor
part of the href attribute value.
hash |
Yes | Yes | Yes | Yes | Yes |
Return the hash property:
var v = areaObject.hash
Set the hash property:
areaObject.hash = anchorname;
Value | Description |
---|---|
anchorname | Set the anchor part of a URL |
A String representing the anchor part of a URL, including the hash sign (#).
The following code shows how to get the anchor part of the URL for a specific area in an image-map.
<!DOCTYPE html>
<html>
<body>
<!-- w w w.j av a 2 s.c o m-->
<img src="http://java2s.com/style/demo/border.png" width="145"
height="126" usemap="#myImageMap">
<map name="myImageMap">
<area id="myArea" shape="circle" coords="124,58,8" alt="myImage"
href="http://example.com#description">
</map>
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
var x = document.getElementById("myArea").hash;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to change the anchor part of a specific area in an image-map.
<!DOCTYPE html>
<html>
<body>
<!-- w ww . ja v a 2 s . co m-->
<img src="http://java2s.com/style/demo/border.png" width="145"
height="126" usemap="#myImageMap">
<map name="myImageMap">
<area id="myArea" target="_blank" shape="circle"
coords="124,58,8" alt="myImage" href="http://example.com#description">
</map>
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myArea").hash = "newhashvalue";
document.getElementById("demo").innerHTML = "changed";
}
</script>
</body>
</html>
The code above is rendered as follows: