Jagd
Jagd

Reputation: 7307

How to find tag in table structure using jQuery

I have the following html:

<table>
  <tr>
    <td>
      <input type="button" id="btnAdd" value="Add" />
      <input type="hidden" id="hdnID" value='209' class="hdn" />
    </td>
  </tr>
  <tr>
    <td>
      <input type="button" id="btnAdd" value="Add" />
      <input type="hidden" id="hdnID" value='210' class="hdn" />
    </td>
  </tr>
  <tr>
    <td>
      <input type="button" id="btnAdd" value="Add" />
      <input type="hidden" id="hdnID" value='211' class="hdn" />
    </td>
  </tr>
</table>

I have a jQuery click event for the add buttons.

$("#btnAdd").click(function ($e) {
  // Need selector here that can find the hidden field (see above) that is found 
  // in the same td as the button that was clicked. For example, if the Add button
  // in the 2nd row was clicked then I need to find the hidden input that has 
  // the value of '210'.

  // Doesn't work... not sure why
  var hdn = $(this).siblings().next();
});

Thanks in advance for helping me through a thick moment...

Upvotes: 0

Views: 139

Answers (1)

ayyp
ayyp

Reputation: 6598

Maybe something like this would work?

("#btnAdd").click(function ($e) {
   var hdn = $(this).parent().next().children('td input');
});

Upvotes: 1

Related Questions