Hamid Reza Salimian
Hamid Reza Salimian

Reputation: 952

Select Element with index greater than 3 and less than 6

i want to select element that its index is greater than 3 and less than 6 ex: $("td:gt(3)") and $("td:lt(6)") ?

Upvotes: 10

Views: 9534

Answers (2)

James Allardice
James Allardice

Reputation: 166021

Just combine the two and it should work:

$("td:gt(3):lt(6)");

You can use any number of pseudo-selectors. They will all apply.

However, note that the slice answer will be far more efficient than this!

Update

The above code is wrong. You need to swap round :lt and :gt because after the gt selector is executed the set of matched elements is reduced and the indexes that :lt applies to are different:

$("td:lt(6):gt(3)");

However, as mentioned above, slice will be better, performance wise. If you're interested in how much better that performance will be, I've put together a quick test. Here's the results (slice is nearly 4 times faster):

enter image description here

Upvotes: 11

dku.rajkumar
dku.rajkumar

Reputation: 18578

make use of slice(start, end)

$('td').slice(3,6)

documentation

Upvotes: 13

Related Questions