Skip to content

Instantly share code, notes, and snippets.

@ubergoober
Created April 16, 2015 12:44
Show Gist options
  • Select an option

  • Save ubergoober/c092a31e437a8eb7a832 to your computer and use it in GitHub Desktop.

Select an option

Save ubergoober/c092a31e437a8eb7a832 to your computer and use it in GitHub Desktop.
Cleanly replace missing images in web page
/*
The below img error snippet will instantly hide any broken image placeholders
although it appears there's extra steps happening here (hidding and unhiding),
The reason is that the split second delay of reloading a new placeholder image
can cause the ugly missing image placeholder to flash if we don't hide it instantly on err.
*/
$("img").error(function () {
$(this).css({visibility:"hidden"});
$(this).attr({src:'/images/theme/no_logo_placeholder.png'});
$(this).css({visibility:"visible"});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment