I have a web page that includes a bunch of images. Sometimes the image isn\'t available, so a broken image is displayed in the client\'s browser.
How do I use jQuery
I use the built in error
handler:
$("img").error(function () {
$(this).unbind("error").attr("src", "broken.gif");
});
Edit: The error()
method is deprecated in jquery 1.8 and higher. Instead, you should use .on("error")
instead:
$("img").on("error", function () {
$(this).attr("src", "broken.gif");
});