chicky chicky - 22 days ago 8
jQuery Question

Find forms with jQuery in table row

i try run a function for each form in a table where the user has checked the checkbox in the first cell of the same row. However i can not find the forms with jQuery.

<table>
<tr>
<td><input type="checkbox" class="checker" value=""></td>
<td>text</td>
<td>text</td>
<td>text</td>
<td><form class="ajax_form"></form></td>
</tr>
<tr>
<td><input type="checkbox" class="checker" value=""></td>
<td>text</td>
<td>text</td>
<td>text</td>
<td><form class="ajax_form"></form></td>
</tr>
<table>


I tried

$('.checker:checkbox:checked').closest('form').each(function() {
...}


also with .find() and .next() but i get no result

Answer

Get the tr which contains the checkbox using closest() method and then find out the form inside using find() method.

$('.checker:checkbox:checked').closest('tr').find('form').each(function() {
   //...
});