Skip to content

Instantly share code, notes, and snippets.

@dkordik
Created October 3, 2013 20:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkordik/6816224 to your computer and use it in GitHub Desktop.
Save dkordik/6816224 to your computer and use it in GitHub Desktop.
Image error events don't bubble, (see http://www.w3.org/TR/DOM-Level-3-Events/#event-type-error ) which can be pretty annoying when you're trying to handle them with any modern event-delegation-y technique. This uses event capturing on supported browsers to trigger a standard bubble-friendly event on the element in question, so you can handle th…
//image error events don't bubble, so we use
// native event capturing, where supported
if (document.addEventListener && !document.bubbleErrors) {
document.addEventListener('error', function (event) {
jQuery(event.target).trigger(event); //bubble it ourselves!
}, true); //true = use event capturing (not bubbling)
document.bubbleErrors = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment