JSFiddle - React, Tailwind, and code Playground
HTML
<!-- element src will fail triggering error event -->
<!-- error will be caught by $(img).on('error'); -->
<img src="image.gif" width="100px" />
JavaScript
$(document).ready(function() {
$('body').on('error', 'img', function(err_event) {
//this will never fire but i feel as though it should
console.log('wont fire anyway'); //errors do not bubble
});
$('body').on('click', 'img', function(ev) {
//clicks bubble correctly and bind to future elements
console.log($(this));
});
$('img').on('error', function(err_event) {
//does not bind to future elements
//but is called once for pre-created element
console.log(['old element', this]);
});
$('body').append('<img src="image.gif" />');
});