The alt
property sets or gets the
value of the alt attribute of an area.
alt |
Yes | Yes | Yes | Yes | Yes |
Return the alt property:
var v = areaObject.alt;
Set the alt property:
areaObject.alt = text;
Value | Description |
---|---|
text | The alternate text for the area |
A String representing an alternate text for the area.
The following code shows how to get the alternate text of a specific area in an image-map.
<!DOCTYPE html>
<html>
<body>
<img src="http://java2s.com/style/demo/border.png"
width="145" height="126" usemap="#myImageMap">
<map name="myImageMap">
<area id="myArea" shape="circle" coords="124,58,8" alt="an image" href="http://example.com">
</map><!-- www .j a v a2s. c o m-->
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
var x = document.getElementById("myArea").alt;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to change the alternate text for a specific area in an image-map.
<!DOCTYPE html>
<html>
<body>
<!-- ww w. j a va2s . co m-->
<img src="http://java2s.com/style/demo/border.png"
width="145" height="126" usemap="#myImageMap">
<map name="myImageMap">
<area id="myArea" shape="circle" coords="124,58,8" alt="An image" href="http://example.com">
</map>
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myArea").alt = "your message";
document.getElementById("demo").innerHTML = "changed";
}
</script>
</body>
</html>
The code above is rendered as follows: