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.
useMap |
Yes | Yes | Yes | Yes | Yes |
Return the useMap property.
var v = imageObject.useMap
Set the useMap property.
imageObject.useMap=#mapname
Value | Description |
---|---|
#mapname | A hash character ('#') plus the name of the map element to use |
A String type value representing the value of the usemap attribute of the image, including the hash character ('#').
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:
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: