Question: I have a page with lots of images on it. My images are loaded from an external server. Usually this server it's loading tooooooooo slow, so my page stay loading until the external server starts running again. I want to put a blank image loaded from mine when the external server is down.

Is there any method to do something like this?

```
if ($("img").load=false) {
 $("img").src="cantload.png";
}

```

Thank you so much, in advance!

Answer: 
If you're using jquery, and this piece of code happens before the binding of the image.

```
$("img").error(function() {
    alert("Could not load image");
});

```

If not, then you could do something like this, which will always work, but will need to be on each image:

```
<img src="image.gif" onerror="alert('Could not load image.')">

```
If you want to activate this function after the elements are already in the DOM, you can use something like this.

```
var defaultSource = 'cantload.png';

$('img').each(function() {
    var originalSource = $(this).attr('src');

    $(this)
        .attr('src', defaultSource)
        .error(function(){
            $(this).attr('src', defaultSource );
        })
        .attr('src', originalSource);
});

```

The above code would bind the inner function to handle the images' loading errors, and then make them all reload. The pictures that are already reloaded won't be actually reloaded again, but those with the errors will trigger the error handler and change the `source attribute` into `cantload.png`

[**jsFiddle Demo**](http://jsfiddle.net/itay1989/a9rXp/)