An advanced selector request $.level()
I was thinking on a tool that would make people's life easier by making a recursive search of elements and give us the deepest level when plainly used.
Level 0
<div id="test">
Level 1
<div>
Level 2
<div class="third">
Level 3
<div>
Level 4
</div>
</div>
</div>
</div>
It should return level count when no index is given;
$("#test").level(); // Which should return 4
also this should select dom at given level index such as;
$(document).ready(function() {
var obj = $("#test").level(2);
alert(obj); // Which should return obj
alert(obj.attr('class')); // Which should return "third"
});
and when there are more than 1 element at that level should return obj array;
Level 0
<div id="test">
Level 1
<div>
Level 2
<div class="third">
Level 3
<div>
Level 4
</div>
</div>
<div></div>
<a></a>
<img />
<span> </span>
</div>
</div>
$(document).ready(function() {
var obj = $("#test").level(2);
alert(obj); // Which should return obj array
alert(obj.length); // Which should return 4 (starting by zero)
});
this would help a lot and solve many turnarounds done with parent(), children(), find() etc..
If its posible to add this feature please contact me (berkeryuceer@yahoo.com).