Skip to content

Instantly share code, notes, and snippets.

@Victa
Created December 30, 2011 11:50
Show Gist options
  • Save Victa/1539485 to your computer and use it in GitHub Desktop.
Save Victa/1539485 to your computer and use it in GitHub Desktop.
jQuery .nextOrFirst()
$.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();
};
@alextegelid
Copy link

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