jQuery的获得最后的tr [英] jquery get the last tr with a th

查看:58
本文介绍了jQuery的获得最后的tr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用jquery如何用th改变最后一个tr的css

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>

推荐答案

作为 xdazz的答案的替代,我是d报价:

As an alternative to xdazz's answer, I'd offer:

$('tr:has(th):last').css('color','blue');

参考文献:

这篇关于jQuery的获得最后的tr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆