How to check if an image is loaded with jQuery

The following jQuery code can be used to detect if an image is loaded successfully or not. In this snippet we are using load and error events.

See All: Equalize Heights of Divs

Click here to view the demo.

//Check whether image is loaded with jQuery
$('#img')
	.load(function(){
		console.log("Image loaded correctly");
	})
	.error(function(){
		console.log("Error in loading image");
	});

If the image is loaded successfully, load event is triggered, else error event is triggered.

1 Comments

Leave a Comment.