Skip to content

Instantly share code, notes, and snippets.

@yoko
Created February 27, 2009 09:55
Show Gist options
  • Save yoko/71383 to your computer and use it in GitHub Desktop.
Save yoko/71383 to your computer and use it in GitHub Desktop.
yet another jQIR.
(function($) {
var options = {
path: '/img'
};
$.replaceImageSetup = function(o) {
options = o;
};
$.fn.replaceImage = function(ext) {
return this.each(function() {
if (!this.id) return;
var self = $(this);
var img = $('<img/>');
var src = options.path+'/'+this.id+'.'+ext;
img.attr({
src: src,
alt: self.text()
});
var a = $('a', self);
var element = a.length ? a.eq(0).html(img) : img;
self.html(element);
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment