jQuery Table How to - Get first table row








Question

We would like to know how to get first table row.

Answer


<!--  ww w. j  av  a 2s .  c  om-->
<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:first").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: