1

http://jsfiddle.net/nbNbp/

I'd like to switch pictures on mouse over, and revert on mouse leave. Can this be done?

  • 2
    Try to pick a different picture next time, some of us are still at work :). – Daniel T. Jan 28 '11 at 03:07
  • http://stackoverflow.com/questions/4824297/how-to-swap-image-src-on-click/4824389#4824389 (its the same code, different events) and a live preview here: http://jsfiddle.net/nbNbp/6/ – ludesign Jan 28 '11 at 03:08

2 Answers2

2
$('#img').hover(function () {
    $(this).data('old-src', $(this).attr('src')).attr('src', 'http://example.com/new_image.jpg');
}, function () {
    $(this).attr('src', $(this).data('old-src'));
});
Alec Gorge
  • 17,110
  • 10
  • 59
  • 71
1

Try this, it works for me:-

$("div#test > img").mouseover(function(){
    $(this).attr('src', 'http://www.google.co.uk/images/logos/ps_logo2a_cp.png');
});
$("div#test > img").mouseout(function(){
    $(this).attr('src', 'http://www.google.co.uk/intl/en_ALL/images/logos/images_logo_lg.gif');
});
evandrix
  • 6,041
  • 4
  • 27
  • 38