Image alt Property - Change the alternate text of an image: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image

Description

Image alt Property - Change the alternate text of an image:

Demo Code

ResultView the demo in separate window

<!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  w  w  .ja va2  s .c  om*/
    document.getElementById("myImg").alt = "newAlternateText";
    document.getElementById("demo").innerHTML = "changed from 'alt message' to 'newAlternateText'";
}
</script>

</body>
</html>

Related Tutorials