我在選擇器中有一個選擇器。我希望內部選擇器只選擇那些也由外部選擇器選擇的元素。 這是我的天真想出了:如何獲得使用此選擇器
$('.some-class').hover(function() {
$(this + '.another-class');
})
換句話說,我想與another-class
的元素和它們是懸停元素的兒童。我怎麼做?
我在選擇器中有一個選擇器。我希望內部選擇器只選擇那些也由外部選擇器選擇的元素。 這是我的天真想出了:如何獲得使用此選擇器
$('.some-class').hover(function() {
$(this + '.another-class');
})
換句話說,我想與another-class
的元素和它們是懸停元素的兒童。我怎麼做?
$('.some-class').hover(function() {
$(this).children('.another-class');
});
這種方法屬於下traversal category,它允許您從當前元素選擇祖先,後代,兄弟姐妹等所有。
$('.some-class').hover(function() {
$(this).find('.another-class');
})
你可以只通過'this'作爲第二個參數'$'。像:'$('。another-class',this);' – Yoshi