Javascript DOM HTML Area alt Property get

Introduction

The alt property sets or gets the value of the alt attribute of an area.

The alt attribute sets an alternate text for an area.

It will show if the image cannot be displayed.

Get the alternate text of a specific area in an image-map:

var x = document.getElementById("myArea").alt;

Click the button to display the alternate text for the myArea area in the image-map.

View in separate window

<!DOCTYPE html>
<html>
<body>

<img src="image1.png" width="100" height="100" usemap="#myFlagMap">

<map name="myFlagMap">
  <area id="myArea" 
        shape="circle" 
        coords="50,50,40" 
        alt="alt message" 
        href="https://www.java2s.com">
</map>//w w  w. j  a  v  a 2  s .com

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

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

<script>
function myFunction() {
  var x = document.getElementById("myArea").alt;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related