jQuery选择第一个和第二个td [英] jQuery Select first and second td
本文介绍了jQuery选择第一个和第二个td的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在每个tr的第一个和第二个td中添加一个类?
How can I add a class to the first and second td in each tr?
<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>
对于第一个交易日,它什么都不做?
For the first td, this does nothing?
$(".location table tbody tr td:first-child").addClass("black");
我还可以使用第二胎吗?
Can I also use second-child?
推荐答案
$(".location table tbody tr td:first-child").addClass("black");
$(".location table tbody tr td:nth-child(2)").addClass("black");
这篇关于jQuery选择第一个和第二个td的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文