Possible Duplicate:
jQuery callback on image load (even when the image is cached)
Is there a way to check if image is loaded by jquery? I have some images with external src and sometime src points to 404 page. Is there a way to check if that image is loaded? and then I can remove it from dom otherwise.
Thanks.
jQuery has a function to deal with this, take a look at .error()
So for example you could attach an .error()
handler to all images and display something else if there is an error, like the source no longer exists:
$('img').error(function() {
$(this).hide();
}).attr("src", "missing.jpg");
Here is a demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With