jquery selecting all elements except the last per group

后端 未结 2 901
被撕碎了的回忆
被撕碎了的回忆 2020-12-30 19:30

I have a table that looks like:

onetwothreelast<
相关标签:
2条回答
  • 2020-12-30 20:22

    Use this:

    $('tr td:not(:last-child)').css('background-color', 'red');
    

    It's saying each <td> that's not the last in that particular <tr>

    0 讨论(0)
  • 2020-12-30 20:28
    $('tr').find('td:not(:last)').css('background-color', 'red');
    

    Translates to: for each element in $('tr') selector, do a find() for all tds that are not last.
    New result is about tds now, so you can apply .css() as wanted.

    0 讨论(0)
提交回复
热议问题