JQuery: find all parents up to a specific parent

Is there a built-in function in jQuery that would allow me to get all parents to a parent with a specific identifier? I have a deeply nested unordered list, and if I have a link to one of the "whether", I need to find all the parent "li" to the root of "ul". If I use parent (), it gives me all parents to the root of the document. One way is to simply write a recursive function and check the parent id, but if there is something built, I would prefer to use this.

+3
source share
2 answers

Parents Until it works for it. I think you need to use jQuery 1.4 to use it.

+3
source

$ ('li'). Nearest ('ul')

+2
source

Source: https://habr.com/ru/post/1729454/


All Articles