Getting a range of elements in one jQuery selector

后端 未结 3 1063
粉色の甜心
粉色の甜心 2020-12-18 23:31

My problem is that I have a table, but I only want a subset of the rows, from first index to last index. I thought you could do it like this:

$(\'table tr:gt         


        
3条回答
  •  轮回少年
    2020-12-19 00:14

    You're pretty close, but the problem in your selector is the :lt(5) filter.

    You would want something like:

    $('table tr:gt(2):lt(2)');
    

    The difference is that by the time the lt() filter is applied, the first three elements were already removed from the set (by the gt() filter). So this will grab the 3rd and 4th element (zero-indexed), instead of the 3rd through the 8th.

提交回复
热议问题