查找具有特定父级的jquery对象的子集

时间:2012-02-14 06:48:36

标签: jquery

我有以下选择器:

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

2 个答案:

答案 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);
});

这可能有用