Skip to content

Instantly share code, notes, and snippets.

@ryankirkman
Created September 19, 2013 22:01
Show Gist options
  • Save ryankirkman/6630488 to your computer and use it in GitHub Desktop.
Save ryankirkman/6630488 to your computer and use it in GitHub Desktop.
A jQuery function that returns the closest previous element, beginning with the current element, matching the provided selector
jQuery.fn.extend({
closestPrev: function(selector) {
if(!selector) return this.prev();
return this.is(selector)
? this
: this.prev(selector) || this.prevUntil(selector).prev();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment