Created
September 19, 2013 22:01
-
-
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
This file contains 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
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