Skip to content

Instantly share code, notes, and snippets.

@duzun
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duzun/187785d63ccb95da8883 to your computer and use it in GitHub Desktop.
Save duzun/187785d63ccb95da8883 to your computer and use it in GitHub Desktop.
findAll() jQuery plugin - a combination of filter, closest and find in one call
/**
* Find selector in this and descendants of this.
* if up == true, search parents as well.
*
*/
;(function (global) {
var $ = global.jQuery || global.Zepto;
$.fn.findAll = function findAll(selector, up) {
var self = this
, search = up ? self.closest(selector) : self.filter(selector)
;
return search.add(self.not(search).find(selector));
} ;
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment