Traversing a table column -jQuery
-
28-04-2021 - |
Domanda
Given a 3 by 3 table, i want to add a class to all the cells of 3rd column .
I have tried doing
$( 'td:eq(3)' ).addclass('special');
$( 'td:eq(5)' ).addclass('special');
$( 'td:eq(8)' ).addclass('special');
but the problem is writing 3 lines of code. Can a single line of code do it ?
Soluzione
$("td:nth-child(3)").addClass('special');
good article about nth-child -
Altri suggerimenti
$('tr > td:nth-child(3)').addClass('special');
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow