Tuesday, September 20, 2011

jQuery Select Consecutive Elements

Use jQuery .slice(). For example:

// select 2nd thru 4th list items
$('li').slice(1, 3);

In fact, you have to use slice in order to select the last, say, 5, elements of a set:

// select last 5 divs of a set
$('div').slice(-5);

No comments:

Post a Comment