Created
December 30, 2011 11:50
-
-
Save Victa/1539485 to your computer and use it in GitHub Desktop.
jQuery .nextOrFirst()
This file contains hidden or 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
$.fn.nextOrFirst = function(selector){ | |
var next = this.next(selector); | |
return (next.length) ? next : this.prevAll(selector).last(); | |
}; | |
$.fn.prevOrLast = function(selector){ | |
var prev = this.prev(selector); | |
return (prev.length) ? prev : this.nextAll(selector).last(); | |
}; |
Good thing you saved this. The source seems to have gone offline. Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
source: http://www.mattvanandel.com/999/jquery-nextorfirst-function-guarantees-a-selection/