Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using jQuery how do I select a range of rows?

Does a jQuery only solution exist for selecting a range of rows from a table?

I know eq, lt, gt exist, but I'm looking for a combination of those selectors.

like image 984
Allain Lalonde Avatar asked Jun 29 '09 18:06

Allain Lalonde


2 Answers

You can apply more than one filter at a time, although the 2nd filter applies to the results of the first, so the following would highlight starting from the 4th row (skips 0..2), and highlight for 3 rows (includes 0..2):

$('#t tr:gt(2):lt(3)').css('background-color', '#f00');
like image 162
great_llama Avatar answered Nov 11 '22 04:11

great_llama


Because :gt() is a jQuery extension... using :gt() cannot take advantage of the performance... For better performance in modern browsers, use $("css-selector").slice(index) instead.

Which says, it's better to use native array method slice to achieve the goal.

$('ul > li').slice(start, end).css("color", "blue")

Direct link: http://api.jquery.com/gt-selector/

like image 41
Lyfing Avatar answered Nov 11 '22 05:11

Lyfing