2011-11-08 64 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

相关问题