Javascript DOM HTML Image useMap Property

Introduction

Set the useMap property:

document.getElementById("planets").useMap = "#myFlagMap";

Click the button to set the value of the usemap attribute of the image to #myFlagMap.

View in separate window

<!DOCTYPE html>
<html>
<body>

<img id="planets" src="image1.png" width="145" height="126">

<map name="myFlagMap">
  <area id="myArea" 
        shape="circle" 
        coords="55,55,40" 
        alt="The Circle" href="https://www.java2s.com">
</map>//from w  w w  . j a  va 2s. co  m

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

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

<script>
function myFunction() {
  var x = document.getElementById("planets").useMap = "#myFlagMap";
  document.getElementById("demo").innerHTML = "The usemap is set, and the link now works!";
}
</script>

</body>
</html>

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

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

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

The useMap property returns a String representing the value of the usemap attribute of the image, including the hash character ("#").




PreviousNext

Related