I want to add the class 'second-col' to all second TD's in each row, but this isn't working:
$('table.tst3 tbody td:eq(1)').addClass('second-col');
Thanks!
I want to add the class 'second-col' to all second TD's in each row, but this isn't working:
$('table.tst3 tbody td:eq(1)').addClass('second-col');
Thanks!
try
$('table.tst3 tbody tr td:nth-child(2)').addClass('second-col');
use nth-child
instead, 'eq
' will Reduce the set of matched elements to a single element
$('table.tst3 tbody td:nth-child(2)').addClass('second-col');
using plain css selection:
$('table.tst3 tbody td + td').addClass('second-col');
Note that if you have more than 2 columns, the ones after the second column will also be selected. So, depending on your markup this may - or may not be relevant: you would need to overwrite these additional columns with another jquery action (using td + td + td). But i thought i'd point to that possibility.