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:Here is a demo