XHanch Studio Log in | Register | Cart

Forum

Notifications
Clear all

[How to] Check for broken images and overcome them with jQuery

XHanch
(@xhanch-alt)
Member Admin

In jQuery, you can simply utilize the error event to find broken images. To overcome them, you may replace them with an informative image or simply hide them.

// To replace broken images with an informative image
$('img').error(function(){
        $(this).attr('src', 'image-not-found.jpg');
});

// To hide broken images
$("img").error(function(){
        $(this).hide();
});
Quote
Topic starter Posted : 25/12/2011 6:37 am
Share:

× Close Menu