Using jquery I need to invoke a function when an image is missing. I need to use jquery as I am match all images that contain a certain path. doing this in jquery is simpler.
I found an example online but cannot establish why it isn't working. Any help would be appreciated.
// tried this and didn't work
$(document).on('error', 'img[src*="/image/path/"]', function() {
alert('error loading image ' + $(this).attr('src'));
});
// to rule out path condition i tried this and it also didn't work
$('body').on('error', 'img', function() {
alert('error loading image ' + $(this).attr('src'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<img src="/my/image/path/foo/bar.jpg" />