Javascript DOM HTML Image complete Property

Introduction

Check to see if the image is finished loading:

var x = document.getElementById("myImg").complete;

Click the button to display whether the browser is finished loading the image or not.

This property returns true if the image has finished loaded, and false if not.

View in separate window

<!DOCTYPE html>
<html>
<body>

<img id="myImg" src="image1.png" alt="The circle" width="100" height="98">
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {/* w  w  w .  j  a  v  a 2 s.c om*/
  var x = document.getElementById("myImg").complete;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The complete property returns whether or not the browser is finished loading an image.

If the image is finished loading, the complete property returns true.

If the image is not finished loading, this property returns false.

The complete property returns true if the loading is finished, otherwise it returns false.




PreviousNext

Related