Let’s say I have two tables that look like this:
TH TH TH TH
TD TD TD TD
TD TD TD TD
and
TH TH TH TH
TH TD TD TD
TH TD TD TD
I’d like to select the 3rd column in each.
At first I was using nth-child as such:
$('table tr td:nth-child(3)')
But that’s not going to work, as 3rd TD is in a different column in each table.
What I need in pseudo code is ‘get the 3rd TD or TH in each row’.
I assume I need to use $.siblings but not entirely sure.
This works for me:
It sets the background color of the 3rd column to ‘red’ (works for both tables).
Note that there is a space between
trand:nth-child(3), and notdin front of:nth-child(3).You can check out this site for sample code and experiment with it.