Showing posts with label imgError. Show all posts
Showing posts with label imgError. Show all posts

Thursday, June 27, 2013

jQuery/Javascript to replace broken images

Handle the onError event for the image to reassign its source using JavaScript:
function(image) {
    image.onerror = "";
    image.src = "/images/noimage.gif";
    return true;
}
<img src="image.png" onerror="imgError(this);"/>
Or without a JavaScript function:
<img src="image.png" onError="this.onerror=null;this.src='/images/noimage.gif';" />