2011-11-08 65 views
0

我在選擇器中有一個選擇器。我希望內部選擇器只選擇那些也由外部選擇器選擇的元素。 這是我的天真想出了:如何獲得使用此選擇器

$('.some-class').hover(function() { 
    $(this + '.another-class'); 
}) 

換句話說,我想與another-class的元素和它們是懸停元素的兒童。我怎麼做?

+2

你可以只通過'this'作爲第二個參數'$'。像:'$('。another-class',this);' – Yoshi

回答

5

使用children() method

$('.some-class').hover(function() { 
    $(this).children('.another-class'); 
}); 

這種方法屬於下traversal category,它允許您從當前元素選擇祖先,後代,兄弟姐妹等所有。

2
$('.some-class').hover(function() { 
    $(this).find('.another-class'); 
}) 
2

此關鍵字代表對象

你需要嘗試這個

jQuery(".another-class", this); 

更多detail

+0

應該指出,這是尋找後代,而不僅僅是兒童。 – Matt

相關問題