jquery get the last tr with a th

核能气质少年 提交于 2019-12-12 02:37:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!