jQuery Selector How to - Select last table row








Question

We would like to know how to select last table row.

Answer


<!--   ww  w  .j  av  a 2 s.  c  o m-->
<html>
  <head>
    <script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type="text/javascript">
      $(document).ready(function(){
          $("tr:last").css("font-style", "italic");
      });
    </script>
  </head>
  <body>
      <table>
        <tr><td>Row 1</td></tr>
        <tr><td>Row 2</td></tr>
        <tr><td>Row 3</td></tr>
      </table>
  </body>
</html>

The code above is rendered as follows: