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>
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>
Share
edited Sep 18, 2012 at 7:25
BoltClock
725k165 gold badges1.4k silver badges1.4k bronze badges
asked Sep 18, 2012 at 7:15
Hello-WorldHello-World
9,55524 gold badges90 silver badges157 bronze badges
1
- And what happens if you do this? And what do you expect to happen? – Nanne Commented Sep 18, 2012 at 7:17
2 Answers
Reset to default 6As an alternative to xdazz's answer, I'd offer:
$('tr:has(th):last').css('color','blue');
References:
:has()
selector.
Find the last th
, and its parent should be the last tr
who has th
.
$("#mytable th:last").parent().css('color', 'blue');
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744912880a4600658.html
评论列表(0条)