开发者

jQuery selector to select 2 and 3rd columns of a table

开发者 https://www.devze.com 2023-02-15 03:24 出处:网络
I am trying to select only 2 and 3 colu开发者_高级运维mns of my \"services\" table. For example,

I am trying to select only 2 and 3 colu开发者_高级运维mns of my "services" table.

For example,

$('table[class="services"] tr td:nth-child(3)')

selects the 3rd column, is there a way to select both 2nd and third columns with a single selector?


$('table[class="services"] tr td:nth-child(3), table[class="services"] tr td:nth-child(2)')


You could split it to avoid repetition of the first part of the selector:

$('table.services tr td').filter(':nth-child(2), :nth-child(3)')

Also note that table.services is the "correct" way to select by class in CSS!


you can do:

$('table.services tr td:nth-child(2), table.services tr td:nth-child(3)')


OR... you can do it like this:

$('table.services tr td:nth-child(n+2):nth-child(-n+3)')

Also useful for a range of columns such as columns 4 to 7 (if needed):

$('table.services tr td:nth-child(n+4):nth-child(-n+7)')
0

精彩评论

暂无评论...
验证码 换一张
取 消