Javascript DOM onload Event on <img> element

Introduction

Using onload on an <img> element.

Alert "Image is loaded" immediately after an image has been loaded:

View in separate window

<!DOCTYPE html>
<html>
<body>

<img src="image1.png" onload="loadImage()" width="100" height="132">

<p id="demo"></p>
<script>
function loadImage() {/*from w  w  w.j  a  va  2 s. c om*/
  document.getElementById("demo").innerHTML = "Image is loaded";
}
</script>

</body>
</html>



PreviousNext

Related