Is there a function similar to jQuery
.closest()
but for traversing descendants and returning only closest ones?
I know that there is
Rob W's answer didn't quite work for me. I adapted it to this which did work.
//closest_descendent plugin
$.fn.closest_descendent = function(filter) {
var found = [];
//go through every matched element that is a child of the target element
$(this).find(filter).each(function(){
//when a match is found, add it to the list
found.push($(this));
});
return found[0]; // Return first match in the list
}