Javascript Reference - HTML DOM Image useMap Property








The usemap attribute specifies an image as a client-side image-map.

The useMap property sets or gets the value of the usemap attribute of an image.

Browser Support

useMap Yes Yes Yes Yes Yes

Syntax

Return the useMap property.

var v = imageObject.useMap

Set the useMap property.

imageObject.useMap=#mapname




Property Values

Value Description
#mapname A hash character ('#') plus the name of the map element to use

Return Value

A String type value representing the value of the usemap attribute of the image, including the hash character ('#').

Example

The following code shows how to get the value of the usemap attribute of an image.


<!DOCTYPE html>
<html>
<body>
<!--from  w  ww  .  j  a v a2 s. c  om-->
<img id="myIDs" src="http://java2s.com/style/demo/border.png" width="100" height="100" usemap="#myIDmap">

<map name="myIDmap">
  <area id="myID" shape="circle" coords="100,50,8" alt="test" href="http://example.com">
</map>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("myIDs").useMap;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to set the useMap property.


<!DOCTYPE html>
<html>
<body>
<img id="myIDs" src="http://java2s.com/style/demo/border.png" width="100" height="100">
<map name="myIDmap">
  <area id="myID" shape="circle" coords="100,50,8" alt="test" href="http://example.com">
</map><!--  w  ww  . j  a va2s  . c om-->
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    var x = document.getElementById("myIDs").useMap = "#myIDmap";
    document.getElementById("demo").innerHTML = "set";
}
</script>

</body>
</html>

The code above is rendered as follows: