Area hash Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Area

Description

The hash property sets or gets the anchor part (URL after the hash sign (#)) of the href attribute value.

When setting the anchor part, do not include the hash sign (#).

Set the hash property with the following Values

Value Description
anchorname Sets the anchor part of a URL

Return Value

A String, representing the anchor part of a URL, including the hash sign (#)

The following code shows how to Return the anchor part of the URL for a specific area in an image-map:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<img src="http://java2s.com/resources/a.png" width="145" height="126" usemap="#myMap">

<map name="myMap">
  <area id="myId" target="_blank" shape="circle" coords="125,60,10" alt="Venus" href="venus.htm#description">
</map>/* w  w  w  .j a  v a  2s .c  om*/

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

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

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

</body>
</html>

Related Tutorials