开发者

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>
</tabl开发者_开发知识库e>

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...


Maybe something like this would work?

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜