jQuery code snippet to either display a default image for those that are broken or detect and hide all broken images. Hide all those red crosses! ;)

// Replace source
$('img').error(function(){
        $(this).attr('src', 'missing.png');
});

// Or, hide them
$("img").error(function(){
        $(this).hide();
});
Tags: jQuery Detect Broken Images, jQuery Hide Broken Images, jQuery remove Broken Images
Sam Deering is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.
Learn Coding Online
Learn Web Development

Start learning web development and design for free with SitePoint Premium!