2011
03.12

Next and Prev Wrap

Ever wanted to do a .next() or .prev() on jQuery and make
it automatically wrap around (so if there’s no next, just choose the first..)?

Well, it’s quite simple, but I made a small script for that.
all you have to do is instead of $(‘element’).next() just write $(‘element’).nextWrap()
and instead of $(‘element’).prev() it’s $(‘element’).prevWrap()

Update!

Now it’s possible to add a selector  (only if you want to :-) )

if you want the next element that is an image, simply write $(this).nextWrap(‘img’)
this will work like the normal jQuery selectors!

Enjoy!

 

nextPrevWrap.js

4 comments so far

Add Your Comment
  1. awesome little function! thanks :)

  2. awesome plugin

  3. can you get image example?

  4. would be a bit hard to describe this with an Image.