delete
delete

Reputation:

How can I use jQuery to change a picture on mouseOver? [JSFiddle]

http://jsfiddle.net/nbNbp/

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

Upvotes: 1

Views: 997

Answers (2)

Alec Gorge
Alec Gorge

Reputation: 17390

$('#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'));
});

Upvotes: 2

evandrix
evandrix

Reputation: 6200

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');
});

Upvotes: 1

Related Questions