jQuery - Check if an image is loaded
William McKeehan
William McKeehan
February 3, 2022

jQuery - Check if an image is loaded

jQuery - Check if an image is loaded

Here’s a snippet I often use when working with images, as it is the best way to know if an image is loaded or not.

var imgsrc = 'img/image1.png';
$('<img/>').load(function () {
alert('image loaded');
}).error(function () {
alert('error loading image');
}).attr('src', imgsrc);

Source: http://tympanus.net/codrops/2010/01/05/some-useful…