开发者

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

开发者 https://www.devze.com 2023-02-07 08:53 出处:网络
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 () {

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

精彩评论

暂无评论...
验证码 换一张
取 消