I have content with broken images, multiple images in each page. Some images have empty src value and some just broken 404 links.
I have been trying to use
<script type="text/javascript">
$(document).ready(function () {
$("img").error(function(){
$(this).hide();
});
});
</script>
It doesn't work as expected, doesn't work in IE, and in chrome I have to reload the page after first load to hide the images. Googled a lot, but all other codes are the same.
Editing the <img>
tag is NOT an option for me.
What is wrong with that code?
Why not just combine DOM events with jQuery:
$("img").each(function () {
var $this = $(this);
this.onerror = function() {
$this.hide();
};
});
This worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With