Monday 6 June 2011

How to identify is image is loaded or not using jquery. If image notloaded loading the default image

When we are working with websites some times images may failed to load. To Identify is the image is loaded or not the follwing is the solution.
Solution 1
function IsImageLoaded() {
if($('#img_id').attr('complete')){
alert('Image is loaded!');
return true;
} else {
return false;
}
}
Solution 2
$("#photo").error(function() {
alert("Image failed to load");
});