问题
using jquery how do alter the css of the last tr with a th
$("#mytable tr").has('th').last().parents('tr').css({'color':'blue'});
HTML
<table border="1" id="mytable">
<tr>
<th>row 1, cell 1</th>
<th>row 1, cell 2</th>
</tr>
<tr>
<th>row 1, cell 1 - change this</th>
<th>row 1, cell 2 - change this</th>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
回答1:
As an alternative to xdazz's answer, I'd offer:
$('tr:has(th):last').css('color','blue');
References:
- :has() selector.
回答2:
Find the last th
, and its parent should be the last tr
who has th
.
$("#mytable th:last").parent().css('color', 'blue');
来源:https://stackoverflow.com/questions/12472110/jquery-get-the-last-tr-with-a-th