JQuery selector to select 2 and 3 columns of a table

I am trying to select only 2 and 3 columns of the "services" table.

For instance,

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

selects the third column, is there a way to select both the second and third columns with one selector?

+4
source share
4 answers
$('table[class="services"] tr td:nth-child(3), table[class="services"] tr td:nth-child(2)')
+7
source

You can break it down to avoid repeating the first part of the selector:

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

Also note that this table.servicesis the β€œright” way to select by class in CSS!

+2
source

You can do:

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

OR ... you can do it like this:

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

Also useful for a range of columns, such as columns 4 through 7 (if necessary):

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

All Articles