jquery用th获得最后一个tr

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

$("#mytable tr").has('th').last().parents('tr').css({'color':'blue'}); 

HTML

 
row 1, cell 1 row 1, cell 2
row 1, cell 1 - change this row 1, cell 2 - change this
row 2, cell 1 row 2, cell 2

作为xdazz答案的替代方案,我提供:

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

参考文献:

  • :has()选择器 。

找到最后一个,它的父母应该是最后一个拥有th

 $("#mytable th:last").parent().css('color', 'blue');