Search code examples
javascriptjqueryhtmldomdom-traversal

Traversing table elements in jQuery


I have a table structure as :

<table id = "cust-id">
  <tr>
    <td> 1</td>
    <td id = "specific_id_re"><a href = "#">link tag</a></td>
  </tr>
  <tr>
    <td> 2 </td>
    <td id = "specific_id"> <a href = "#">link tag</a></td>
  </tr>
</table>

I am trying to use jquery to access each of the table row columns that have an id and a link tag, but I am falling short. The best I have been doing is:

 $('#cust-id').children().children().children() ; // to get access to the td elements ?

Any suggestions on what I should read or how I ought to approach this ?

Thanks Parijat Kalia


Solution

  • $('#cust-id td[id] a').each(function () {
      var td = $(this).closest('td');
      // do what you want
    });