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!
My team mate Edna Piranha is not only an awesome hacker; she's also a fantastic philosopher! Communication and online interactions is a subject that has kept her mind busy for a long time, and it has also resulted in a bunch of interesting experimental projects...
It's been quite a while since I've written a PHP grabber and the itch finally got to me. This time the victim is the International Movie Database, otherwise known as IMDB. IMDB has info on every movie ever made (or so it seems). Their...
Back when I created client websites, one of the many things that frustrated me was the initial design handoff. It would always go like this:
Work hard to incorporate client's ideas, dream up awesome design.
Create said design, using Lorem Ipsum text
Send initial design concept to the client...
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.