You really need to learn CSS sprites to switch the background on hover. But if you need to do this in jQuery, something like this should do it. Just change the source image to your liking (also preload the hover image):
var link = $('a'),
img = link.children('img'),
orig = img.attr('src'),
over = 'over.png',
temp = new Image();
temp.src = over;
link.hover(function() {
img.attr('src',over);
},function() {
img.attr('src',orig);
}
source
share