How can I use jQuery to change a picture on mouseOver? [JSFiddle]
http://jsfiddle.net/nbNbp/
I'd like to switch pic开发者_运维知识库tures on mouse over, and revert on mouse leave. Can this be done?
$('#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'));
});
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');
});
精彩评论