1
2
3
4
5
6
7
8
9
//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);