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?
Columns can be selected using column(). select() or columns(). select() API methods. You can enable single or multiple items selection using select.
In jQuery, you can select multiple elements by separate it with a comma “,” symbol.
Projects In JavaScript & JQueryjQuery uses CSS selector to select elements using CSS. Let us see an example to return a style property on the first matched element. The css( name ) method returns a style property on the first matched element.
$('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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With