JQuery: get all input in table and serialize

Given the following table structure, how would I get all the input shafts in the table when clicked .button?

<table>
    <tr>
      <td><input value="1" name="A" type="text" /><td>
    </tr>
    <tr>
      <td><input value="2" name="B" type="text" /><td>
    </tr>
    <tr>
      <td><input value="3" name="C" type="text" /><td>
    </tr>
    <tr>
      <td><div class="button"></div><td>
    </tr>
</table>

This is the jquery that I have so far:

$('.button').click(function() {
    alert($(this).parent('table').('input').serialize());
});

The function does not work, although it does not find the input in the table, I think ...

+3
source share
2 answers

tableis not the parent of the button, tdis ... try:

$(this).closest('table').find('input').serialize()

+7
source

not very direct, but should give you an understanding:

http://jsfiddle.net/5D5NG/3/

+1
source

All Articles