Solved (view)
Well, I think I decided (except in extreme cases) using the following:
function findByDepth(parent, child, depth){
var children = $();
$(child, $(parent)).each(function(){
if($(this).parentsUntil(parent, child).length == (depth - 1)){
children = $(children).add($(this));
}
});
return children;
}
var threeDeep = findByDepth('#parent', '.child', 3);
However, someone must accept the accepted answer here, and I am not going to answer it myself and hide with your well-established representative. So, if someone wants to add something, for example, to give an idea about the optimization of this function (before I leave and $.extend()), I will most likely mark your answer correctly, otherwise we will return to marking who was first in my original question.
By the way, check this in the script: http://jsfiddle.net/5PDaA/
Sub update
@CAFxX, , , , , querySelectorAll , . , , guff:
$.fn.extend({
'findAtDepth': function(selector, depth){
var depth = parseInt(depth) || 1;
var query = selector;
for(var i = 1; i < depth; i++){
query += (' ' + selector);
}
return $(query, $(this)).not(query + ' ' + selector);
}
});
, , , selector, - .
Update
, , . , ; , , ( ), . , . , +1 :
( , ), ( ) .
(XML ):
<parent>
<child>
<child>
<child>
<child></child>
</child>
<child>
<child></child>
</child>
</child>
<child>
<child></child>
</child>
</child>
</parent>
2, 2.X. 4 4.X ..
jQuery, " " , ? :
. . .child .
. , , , , .
// HTML
<div id="parent">
<div>
<div class="child">
<div>
<div class="child">
</div>
</div>
</div>
<div class="child">
<div>
<div class="child">
</div>
</div>
</div>
</div>
</div>
$('#parent').find('.child:generation(1)');
#parent, jQuery :first , .child.