Search code examples
jqueryhtml-tablen-tier-architecture

addclass to first-level elements only


HTML:

<table id="table-1">
  <tr>

    <td>
      <table>
        <tr>
          <td>content</td>
        <tr>
      </table>   
    </td>

    <td>Content</td>

  </tr>
</table>

Is it possible to addclass 'td-1' to ONLY first-level TD's of #table-1 and not all?


Solution

  • $('#table-1 td:first').addClass('td-1');
    

    check: http://docs.jquery.com/Selectors/first

    This will add the class only to first td in first tr,

    Sinan.

    EDIT:

    `$('#table-1>tbody>tr>td').addClass('td-1');` 
    

    it should be as above for all first level td items.