tags:

views:

64

answers:

2

Is there a built in function in jQuery that would allow me to get all the parents up to a parent with specific Id? I have a deeply nested unordered list, and if I have a reference to one of the "li" I need to find all parent "li" up to a root "ul". If I use parents() it gives me all parents up to a root of document. One way would be just to write recursive function and check for id of the parent, but if there is something built in I would rather use that.

A: 

Parents Until should work for that. I think you need jQuery 1.4 to use it though.

rosscj2533
Cool, I'll have to upgrade to 1.4
epitka
Yeah, it definitely is version 1.4 only. Upgrading (hopefully) shouldn't be a big problem though.
rosscj2533
A: 

$('li').closest('ul')

David Williams
He wants all the parents, not just the top most.
John Sheehan