Question

Autobots

How Can I Make Images Completely Remove Themeselves When They Failed to Load Properly?

Asked by Autobots 7 months ago load images

Answers

Joel Reyes
0
 
You can use the onerror event which is automatically triggered when an image fails to load properly.

For Example:

<img src="http://cdn.qhub.com/image.png" alt="image" onerror="this.parentNode.removeChild(this)" />

Or you can use this for Firefox/Chrome:

Var imgs = document.getElementsByTagName('img')
        for(var i=0,j=imgs.length;i<j;i++){
                imgs[i].onerror = function(e){
                this.parentNode.removeChild(this);
        }
}

by Joel Reyes 6 months ago

Answer this question

How Can I Make Images Completely Remove Themeselves When They Failed to Load Properly?

0 errors found:

 
0