Is it possible to create custom jQuery selectors that navigate ancestors? e.g. a :closest or :parents selector
问题 I write a lot of jQuery plugins and have custom jQuery selectors I use all the time like :focusable and :closeto to provide commonly used filters. e.g. :focusable looks like this jQuery.extend(jQuery.expr[':'], { focusable: function (el, index, selector) { return $(el).is('a, button, :input[type!=hidden], [tabindex]'); }; }); and is used like any other selector: $(':focusable').css('color', 'red'); // color all focusable elements red I notice none of the jQuery selectors available can