Select Element with index greater than 3 and less than 6

喜夏-厌秋 提交于 2019-12-01 14:41:03

问题


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


回答1:


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):




回答2:


make use of slice(start, end)

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

documentation



来源:https://stackoverflow.com/questions/8881055/select-element-with-index-greater-than-3-and-less-than-6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!