Je veux donner à TOUTES les classes spécifiques (y compris les
$("table tr:first-child td:first-child").addClass("first-col-cell"); $("table tr:last-child td:last-child").addClass("last-col-cell");
..mais ça ne semble pas fonctionner.
J’apprécierais toute aide.
EDIT: Votre sélecteur était assez proche:
Si les éléments importent, vous ne savez pas comment traiter les colspans.
blah blah blah
Essayez de le décomposer un peu, la traversée que vous faites est incorrecte
// This will take the first child which is a TD, within any TR in the table. $("table tr td:first-child").addClass("first-col-cell"); // This will take the first child which is a TR within the table. $("table tr:first-child").addClass("first-col-cell"); // Just like the above, except now we're doing the last occurances $("table tr td:last-child").addClass("last-col-cell"); $("table tr:last-child").addClass("last-col-cell");
Ensuite, nous devons simplement nous assurer que la marge est bonne
1 1 1 1 2 2 2 2 3 3 3 3
Et puis jQuery devrait passer par chacun avec les résultats suivants
1 1 1 1 2 2 2 2 3 3 3 3