2013-07-04 71 views
0
$(".test").hover(function(){ 
    $(this).addClass("move");   
}) 

以上jQuery需要一些修復。我CSS選擇目前這樣的:jQuery - 懸停一個元素來添加一個類到它?

.test .selectme 

和懸停在.test元素目前其結果是:將鼠標懸停在.test元素時

.test.move .selectme 

我試圖讓這個來代替:

.test .selectme.move 

所以基本上我需要jQuery給.selectme當我將鼠標懸停在parent.test上時,這是10級。

+0

你都知道了'的:hover'在CSS右僞類?你可以做'.test:hover .selectme',而不是用jQuery添加類... – xec

+0

是的,我知道。但在我的情況下,我需要jQuery。 – Sunny

+0

我可以問一下你需要什麼課程嗎? – xec

回答

5

你需要找到裏面menuselectme項目,然後將該類添加到它

$(".menu").hover(function(){ 
    $(this).find('.selectme').addClass("move"); //You may use toggleClass('move') if you want to remove the class when the mouse leaves menu item 
}) 
1
$(".test").hover(function(){ 
    $('.selectme',this).addClass("move"); //This is simpler, find the selectme that's inside of .test 
}) 
相關問題