Last active
January 16, 2018 03:53
-
-
Save johnbocook/4eba30f424c4a678740f to your computer and use it in GitHub Desktop.
Use jQuery to deal with missing images
This file contains hidden or 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
| // Hide the image on error | |
| $("img").error(function(){ | |
| $(this).hide(); | |
| }); | |
| // Change the missing image to a default image | |
| $('img').error(function(){ | |
| $(this).attr('src', 'no-image.jpg'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment