2013-08-21 84 views
0

我有以下的html:mousoever和設置背景色

<img class="img-polaroid img-hover" src="/images/147/09e65aac97caf00c5414593719d0e1b4-medium.jpg?1376027188" background-color="yellow"> 

和CSS

.img-hover:hover{ 
    background-color: $green-highlight-1; 
    cursor: pointer; 
} 

,想轉換爲jQuery的,使我們擁有了顏色更多的控制權(和動畫它)。像這樣:

$('.img-hover').on('mouseover', function(){ 
    console.log("here i am in img-hover"); 
    $(this).attr('background-color','yellow'); 
}); 

但這不工作(console.log工程)。我該如何設置背景顏色?

回答

1

你想

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

啊,是的,THX ....很長一段時間。必須等待幾分鐘 – timpone

0

使用css而不是attr

$('.img-hover').on('mouseover', function(){ 
    console.log("here i am in img-hover"); 
    $(this).css("background-color", "yellow"); 
}); 
0

使用.css()方法,如:

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