Skip to content

Instantly share code, notes, and snippets.

@jakearchibald
Created March 19, 2012 10:44
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakearchibald/2107184 to your computer and use it in GitHub Desktop.
Save jakearchibald/2107184 to your computer and use it in GitHub Desktop.
document.body.addEventListener('error', function(event) {
if ( event.target.nodeName.toLowerCase() == 'img' ) {
// an image on the page failed to load
}
}, true);
@patik
Copy link

patik commented Mar 19, 2012

You might consider testing the tag's name with regular expressions for better performance (see jsperf tests here and here).

if ( /^img$/i.test(event.target.nodeName) ) {

@jakearchibald
Copy link
Author

Interesting... but if you're testing enough elements to see a real world difference, you've probably got bigger problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment