using jQuery's .next
function I want to show next 2 items. By default it selects only just next item.
I need control, like sometimes I need next 2, sometime next 3
using jQuery's .next
function I want to show next 2 items. By default it selects only just next item.
I need control, like sometimes I need next 2, sometime next 3
You can use .nextAll()
and a :lt()
selector, for example:
.nextAll(':lt(2)') //next 2
.nextAll(':lt(3)') //next 3
Try it out here. If you need it to be programmatic (instead of string concatenation) and change it easily, use .slice()
instead:
.nextAll().slice(0, 2) //next 2
.nextAll().slice(0, 3) //next 3
This method allows you to pass as a parameter the number you need a bit easier. You can test it here.
Use .nextAll
instead of .next
to get all following siblings, and then use .slice
to narrow that down to a range.