Is there a function similar to jQuery .closest() but for traversing descendants and returning only closest ones?
I know that there is .find() function, but it returns all possible matches, not closest.
Edit:
Here is definition of closest (at least for me):
In first place all childrens are traversed, then each individuals childrens are traversed.
In example given below id='2' is closest .closest descendants of id="find-my-closest-descendant"
<div id="find-my-closest-descendant">
<div>
<div class="closest" Id='1'></div>
</div>
<div class="closest" Id='2'></div>
</div>
Please see JSfiddle link.
According to your definition of
closest, I’ve written the following plugin: