function addImageErrorHandlers() { if(typeof(jQuery) != 'undefined') { // Add error handlers to all images with image_error class, and remove the class. jQuery('img.image_error').removeClass("image_error").error(function(){ // The next span will contain the URL of another image. var failoverImage = jQuery(this).next('span.image_error'); if (1 == failoverImage.length && failoverImage.attr('title').length > 0) { // Assign a new URL to this image. jQuery(this).attr('src', failoverImage.attr('title')); // Remove this failover image, so move on to the next one in the chain. failoverImage.remove(); } }); } }