Jquery 鼠标盖和设置背景色

Jquery 鼠标盖和设置背景色,jquery,css,Jquery,Css,我有以下html: <img class="img-polaroid img-hover" src="/images/147/09e65aac97caf00c5414593719d0e1b4-medium.jpg?1376027188" background-color="yellow"> 并且希望转换为jquery,这样我们就可以更好地控制颜色(并设置动画)。比如: $('.img-hover').on('mouseover', function(){ console.l

我有以下html:

<img class="img-polaroid img-hover" src="/images/147/09e65aac97caf00c5414593719d0e1b4-medium.jpg?1376027188" background-color="yellow">
并且希望转换为jquery,这样我们就可以更好地控制颜色(并设置动画)。比如:

$('.img-hover').on('mouseover', function(){
    console.log("here i am in img-hover");
   $(this).attr('background-color','yellow');
});
但这不起作用(console.log起作用)。我如何这样设置背景色

你想要什么

$(this).css('background-color','yellow');

使用
css
而不是
attr

$('.img-hover').on('mouseover', function(){
    console.log("here i am in img-hover");
   $(this).css("background-color", "yellow");
});
使用
.css()
方法,如:

$('.img-hover').mouseover(function(){
  $(this).css('backgroundColor', ' yellow');
});
$('.img-hover').mouseover(function(){
  $(this).css('backgroundColor', ' yellow');
});