jQuery Table How to - Select table cell whose index is less than 1








Question

We would like to know how to select table cell whose index is less than 1.

Answer


<!--from  w ww .java 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(){
          $("td:lt(1)").css("color", "red");
      });
    </script>
  </head>
  <body>
       <table border="1">
        <tr><td>Row</td></tr>
        <tr><td>Row</td></tr>
        <tr><td>Row</td></tr>
        <tr><td>Row</td></tr>
      </table>
  </body>
</html>

The code above is rendered as follows: