tags:

views:

222

answers:

2

Given an unorder nested list, if one finds a first occurrence of the "li", how does one find all the siblings that are on the same level?

root.find('li:first')...?

Update: My question was not formulated correctly. I actually need to know following. If I have a reference to element, how do I find elements siblings and create a set that will include element itself and the siblings of the same element type, in this case 'li'?

+3  A: 

If I understand you correctly, you would use the siblings method:

$(this).siblings("li");
Jonathan Sampson
+4  A: 

If you want to include the original element as well, you'll need

$(this).siblings("li").andSelf();
Blair Mitchelmore
+1 - spot on answer
Russ Cam