2012-02-14 22 views
0

我有以下選擇:查找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

+0

能否請您解釋一下? – 2012-02-14 06:52:04

+0

@nDudani增加了一段澄清 - 我希望這可以讓事情變得清晰! – 2012-02-14 06:54:11

回答

2

試試這個,

var foo = $('.someClass'); 
var rows = $('.rows'); 
rows.each(function (index, element) { 
    var specificFoo = element.find(foo); 
}); 
+0

謝謝!! – 2012-02-14 07:14:39

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

這可能工作

+1

謝謝,但實際上它差不多和@ParagGajjar的答案一樣 – 2012-02-14 07:24:06

相關問題