Javascript examples for DOM HTML Element:Image
The alt property sets or gets the alt attribute of an image.
Set the alt property with the following Values
Value | Description |
---|---|
text | Sets an alternate text for an image. |
A String, representing the alternate text of the image
The following code shows how to return the alternate text of an image:
<!DOCTYPE html> <html> <body> <img id="myImg" src="http://java2s.com/resources/a.png" alt="alt message" width="107" height="98"> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from w ww . java 2s. c om*/ var v = document.getElementById("myImg").alt; document.getElementById("demo").innerHTML = v; } </script> </body> </html>