我有以下选择器:
var $foo = $('.someClass');
var $rows = $('.rows');
$rows.each(function (index, element) {
var $row = $(element);
var $specificFoo = /* how to I get the specific foos, where $row is their parent */;
});
有机会这样做吗?
澄清:
有些$foo
是$row
的孩子 - 我正在尝试查询此特定子集。查看我的example
答案 0 :(得分:2)
试试这个,
var foo = $('.someClass');
var rows = $('.rows');
rows.each(function (index, element) {
var specificFoo = element.find(foo);
});
答案 1 :(得分:2)
var $tests = $('.test');
var $divs = $('div');
$divs.each(function (index, element) {
var $div = $(element);
//var $test = $($tests, $divs); // won't work
var $test = $div.find( $tests );
alert($test.length);
});
这可能有用