Created
September 23, 2016 18:54
-
-
Save joelremix/facaf21800983dbdcb9e37f22304b65c to your computer and use it in GitHub Desktop.
jQuery: Check Broken Images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
// Looping through all image elements | |
$("img").each( function () { | |
var element = $(this); | |
$.ajax({ | |
url:$(this).attr('src'), | |
type:'get', | |
async: false, | |
error:function(response){ | |
var replace_src = "images/noimage.png"; | |
// Again check the default image | |
$.ajax({ | |
url: replace_src, | |
type:'get', | |
async: false, | |
success: function(){ | |
$(element).attr('src', replace_src); | |
}, | |
error:function(response){ | |
$(element).hide(); | |
} | |
}); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment