2014-05-12 92 views
0

我已經在a:hover上設置了背景圖像,我需要在mouseover(基於條件)的基礎上對另一圖像進行覆蓋。使用jQuery更改懸停的背景

我想這一點,但它不工作:

$("a").mouseover(function() { 
    $(this).css('background-image', 'url(../images/new2.png'); 
}); 

...它仍然顯示了使用CSS應用到a:hover之一。

+1

你能證明這一點「不工作'?因爲它真的應該,我想。 –

+1

您錯過了url的結尾括號 – mohamedrias

+0

$(this).css('background-image','url(../ images/new2.png)');將做的伎倆 – mohamedrias

回答

4

您需要爲您的網址

+0

就是這樣!男人,我不應該工作得這麼晚,發生這麼多愚蠢的錯誤! – 3zzy

0

延伸@sahbeewah答案右括號,關閉支架爲您的網址

$("a").mouseover(function() { 
    $(this).css('background-image', 'url(../images/new2.png)'); 
}); 

您還可以使用CSS

a:hover{ 
    background-image : url(../images/new2.png); 
}