jQuery: fallback

more at: http://stackoverflow.com/a/17352656/1250044

HTML

<img src="/foo" width="240">
<img src="/bar" width="320">

JavaScript

;(window.jQuery || window.Zepto).fn.fallback = function (fallback) {
    return this.one('error', function () {
        var self = this;
        this.src = (fallback || 'http://lorempixel.com/$width/$height')
        .replace(/\$(\w+)/g, function (m, t) { return self[t] || ''; });
    });
};

$('img').fallback('http://dummyimage.com/$widthx$height&text=$src');