Demo for jQuery plugin: closestDescendant

Get the first element(s) that matches the selector by testing the element itself and traversing down through its descendants in the DOM tree level by level. It use a breadth first search (BFS), that mean it will going deeper in a subtree only until the first matching descendant was found in the current subtree.

View the Project on GitHub tlindig/jquery-closest-descendant

.closestDescendant(selector [, findAll] )

parent
child 1
child 1.1
child 1.1.1 class="c"
child 2 class="c"
child 3 class="c"
child 3.1 class="c"

Result:

jQuery('#parent').closestDescendant(".c")
jQuery('#parent').find(".c:first")
jQuery('#parent').closestDescendant(".c", true)
jQuery('#parent').find(".c")