Reputation: 6427
I am trying to select only 2 and 3 columns 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?
Upvotes: 5
Views: 15240
Reputation: 729
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)')
Upvotes: 0
Reputation: 146310
you can do:
$('table.services tr td:nth-child(2), table.services tr td:nth-child(3)')
Upvotes: 1
Reputation: 33388
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!
Upvotes: 3
Reputation: 46008
$('table[class="services"] tr td:nth-child(3), table[class="services"] tr td:nth-child(2)')
Upvotes: 10