Remove Broken Images Using Dojo
In an effort to get better with the Dojo Toolkit, I've decided to port yet another one of my previous posts: Remove Broken Images Using MooTools or jQuery. Broken images are an eyesore to any website so there's no point to keeping them in the page. Here's how you can remove them on the client side.
The Dojo JavaScript
dojo.ready(function() {
dojo.query('img').forEach(function(img){
dojo.connect(img,'onerror',function() {
dojo.destroy(img);
});
});
});
Just as simple as jQuery and MooTools -- just a different syntax!
Sooner or later you'll run across a regular expression. With their cryptic syntax, confusing documentation and massive learning curve, most developers settle for copying and pasting them from StackOverflow and hoping they work. But what if you could decode regular expressions and harness their power? In...
MooTools has always gotten a bit of grief for not inherently using and standardizing namespaced-based JavaScript classes like the Dojo Toolkit does. Many developers create their classes as globals which is generally frowned up. I mostly disagree with that stance, but each to their own. In any event...
If you're still rocking an iPhone and fancy taking a photo every now and then, you'd be crazy not to be using an app called Instagram. With Instagram you take the photos just as you would with your native iPhone camera app, but Instagram...
A while back I debuted a tasteful mouseover/mouseout technique called link nudging. It started with a MooTools version and shortly thereafter a jQuery version. Just recently Drew Douglass premiered a jQuery plugin that aimed at producing the same type of effect.
Some streamlining of your methods:
Nice site by the way :) Keep up the Dojo posts :)
@Karl Tiedt: Applied to a collection — very nice! I’ll keep that in mind from this point forward.
Would you happen to have code to do this with prototype?
I wish images would fire an event if they didn’t load then we could put something in it’s place instead of going through every image checking. Kind of slow…
@Ben: They do — they fire an
onError
event.