We can use closest(selector)to find the first ancestor element that matches the selector. It moves up the DOM tree until it finds a match for the selector. But what if I want to travel down the DOM tree until it finds a match for the selector? Is there a jQuery function for this? Or do I need to implement this using a width search?
Give an example. For the DOM tree below,
<div id="main">
<div>
<ul>
<li>
<ul>
</ul>
</li>
</ul>
<ul>
</ul>
</div>
</div>
how to do something like $('#main').closestDescendants('ul')?
source
share