我在选择器中有一个选择器。我希望内部选择器只选择那些也由外部选择器选择的元素。 这是我的天真想出了:如何获得使用此选择器
$('.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