Specify multiple columns with nth-child ()

I use nth-child in my jquery selector to determine the columns to change. I have 5 columns (1-5) and I want to change only 2,3 and 4. Is there a way to do this with nth-child? Sort of:

$('#example tbody tr td:nth-child(2||3||4)')

I tried several combinations, but nothing works. Im pretty new to jQuery selectors any help you could pounce on me would be greatly appreciated.

Regards, Joe Chin

+5
source share
3 answers
$('#example tbody tr td:not(:last-child, :first-child)')
+5
source

You can use .nextUntil()as follows:

$('#example tbody tr td:nth-child(1)').nextUntil(':nth-child(5)');​​​​​​​​​​​​​​​​​​​​​​​
+6
source

I would use a slice, it is more dynamic.

$('#example tbody tr td').slice(1,4)

It uses the API for the slice method.

+1
source

All Articles