Created
December 19, 2016 16:48
-
-
Save yratof/8dfd44516641f7542974efcd4479dc53 to your computer and use it in GitHub Desktop.
Failed iamges in JS
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
function imgLoaded(imgElement) { | |
return imgElement.complete && imgElement.naturalHeight !== 0; | |
} | |
$ = jQuery; | |
$('img').each( function(){ | |
if ( ! imgLoaded( $(this) ) ) { | |
$(this).addClass('failed'); | |
}}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment