I made a small closestDesc plugin for this.
(function( $ ) { $.fn.closestDesc = function(selector) { var selection = []; var query = function () { this.children().each(function() { if ($(this).is(selector)) { selection.push(this); } else { query.call(this); } }); }; query.call(this); return this.pushStack(selection, "closestDesc", selector); }; })(jQuery);
This captures all the closest descendants matching the selector.
Fiddle: http://jsfiddle.net/uGR2a/9/
source share