Image useMap Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image

Description

The useMap property sets or gets the usemap attribute of an image, which identifies if an image is used as a client-side image-map.

Set the useMap property with the following Values

ValueDescription
#mapname A hash character ("#") plus the name of the map element

Return Value

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

The following code shows how to Set the useMap property:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<img id="planets" src="http://java2s.com/resources/a.png" width="145" height="126">

<map name="myMap">
  <area id="myId" shape="circle" coords="125,60,10" alt="alt message" href="http://java2s.com">
</map>/*w ww  .  j  a  v a2s. c o  m*/

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

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

<script>
function myFunction() {
    var x = document.getElementById("planets").useMap = "#myMap";
    document.getElementById("demo").innerHTML = "The usemap is set!";
}
</script>

</body>
</html>

Related Tutorials