开发者

jQuery: find all the parents up to a specific parent

开发者 https://www.devze.com 2022-12-17 22:26 出处:网络
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\"

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 a开发者_运维技巧ll 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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号