A while back I wrote a post called Send Email Notifications for Broken Images Using MooTools Ajax. Looking back on that post, I failed to address the image itself. After some thought I’ve decided it would be best to remove the broken image from the page all together. Below you’ll find how to do so using MooTools or jQuery.
The MooTools Javascript
$$('img').addEvent('error',function() {
this.dispose();
});
The MooTools way of removing elements from the page is Element.dispose().
The jQuery Javascript
$('img').error(function() {
$(this).remove();
});
The jQuery way of removing elements from the page is jQuery.remove().
Removing a broken image is a great way of preventing the user from seeing a shortcoming in your website.Don't forget to follow me on Twitter and be sure to visit Script & Style for the best Javascript and CSS articles around!
Blog traffic is booming. Sponsor the David Walsh Blog and get your brand in front of several thousand users per day!Remove Broken Images Using MooTools or jQuery
Related posts:
- Send Email Notifications for Broken Images Using jQuery Ajax
- Send Email Notifications for Broken Images Using MooTools Ajax
- Implement MooTools’ Elements.addEvent in jQuery
- Implementing jQuery-Like Event Syntax in MooTools
- Color Palette Generator Using jQuery


Recent comments
20 weeks 5 days ago
22 weeks 2 days ago
22 weeks 2 days ago
22 weeks 2 days ago
22 weeks 2 days ago
22 weeks 2 days ago
22 weeks 2 days ago
22 weeks 2 days ago
22 weeks 2 days ago
22 weeks 2 days ago