Tips: Replace Missing Images using JQuery

Posted by anup.narkhede on March 26, 2009

Checking for non-existing images and replacing them by placeholders is simple when the images are handled on server (db/filestore). However, for externally linked images, we can do something like this using JQuery:

This script will replace the broken image urls with ‘/images/noimage.jpg’.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. Carlos JĂșnior Fri, 27 Mar 2009 16:09:23 PDT

    Or even better:

    1.
    2. $(”img”).one(”error”, function () {
    3. $(this).attr(”src”, “/images/noimage.jpg”);
    4. });
    5.

    This will automatically unbind the event after it’s first execution :D

Comments