I’m trying to detect broken images in jQuery, in which case I want to remove them and replace by it’s alt text.
I’m using following code I found here on SO;
$(document).ready(function(){
$('img.logoimg').error(function() {
$(this).unbind("error");
$(this).parent().prepend("<strong>"+$(this).attr("alt")+"</strong>");
$(this).remove();
});
//...
}
This works fine in FF.
In Chrome however, the browser still shows a square indicating a broken image.
It seems as if the error event fires too late to detect the broken image.
Can I have it fire sooner? Is there something else wrong with the code?
[Edit] Added a solution below. Anyone able to explain this earns solution to this question.
I have identified the problem by elimination. It’s not where you would think.
Under my script tags, I had a Google Ads code:
It’s the last call :
GA_googleFetchAds()that kills it. Removing that call seems to solve my issue. Strangely.I’ve now solved it like so:
Anyone with a reasonable explanation earns my eternal respect and gratitude.