Reputation: 952
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
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):
Upvotes: 11