Skip to content

Instantly share code, notes, and snippets.

@vosnikopa
Created September 14, 2012 12:59
Show Gist options
  • Save vosnikopa/3721767 to your computer and use it in GitHub Desktop.
Save vosnikopa/3721767 to your computer and use it in GitHub Desktop.
Detecting broken images with JavaScript
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript">
</script>
$(document).ready(function(){
$("img").each(function(index) {
$(this).error(function() {
$(this).unbind("error").attr("src", "/images/NoImage.png"); // If you want to replace with any blank image.
$(this).hide();//You can simply Hide it using this.
});
$(this).attr("src", $(this).attr("src"));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment