Skip to content

Instantly share code, notes, and snippets.

@Victa
Created December 30, 2011 11:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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();
};
@Victa
Copy link
Author

Victa commented Dec 30, 2011

@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