如何在每个tr中的第一个和第二个td中添加一个类?
<div class='location'> <table> <tbody> <tr> <td>THIS ONE</td> <td>THIS ONE</td> <td>else</td> <td>here</td> </tr> <tr> <td>THIS ONE</td> <td>THIS ONE</td> <td>else</td> <td>here</td> </tr> </tbody> </table> </div>
对于第一个td,这不做什么?
$(".location table tbody tr td:first-child").addClass("black");
我也可以使用二胎吗?
解决方法
$(".location table tbody tr td:first-child").addClass("black"); $(".location table tbody tr td:nth-child(2)").addClass("black");