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'?
If you want to include the original element as well, you'll need
$(this).siblings("li").andSelf();
Edit: jQuery has deprecated andSelf. This is still the top answer, so for future use addBack might be what you want
$(this).siblings("li").addBack();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With