-
-
Save jesse1981/5537111 to your computer and use it in GitHub Desktop.
Find closest child element which matches given filter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.closest_descendent = function(filter) { | |
var $found = $(), | |
$currentSet = this; // Current place | |
while ($currentSet.length) { | |
$found = $currentSet.filter(filter); | |
if ($found.length) break; // At least one match: break loop | |
// Get all children of the current set | |
$currentSet = $currentSet.children(); | |
} | |
return $found.first(); // Return first match of the collection | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment