Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
108
rated 0 times [  112] [ 4]  / answers: 1 / hits: 24555  / 14 Years ago, mon, october 11, 2010, 12:00:00

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


More From » jquery

 Answers
161

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.


[#95364] Thursday, October 7, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gerardamosy

Total Points: 600
Total Questions: 116
Total Answers: 102

Location: Ukraine
Member since Tue, May 30, 2023
1 Year ago
;