tags:

views:

50

answers:

2

How to remove using jquery html table row after checking checkbox that in this row?

<table  id="mainTable">
    <tr>
        <th>
            name
        </th>
        <th>
            remove
        </th>
    </tr>
    <tr>
        <td>
            <input type="text" />
        </td>
        <td>
            <input type="checkbox" id="chb1" />
        </td>
    </tr>
    <tr>
        <td>
            <input type="text" />
        </td>
        <td>
            <input type="checkbox" id="chb2" />
        </td>
    </tr>
</table>

for example, i select checkbox with id chb2, and want that second row is removed

+1  A: 

Try this:

$('input:checkbox').click(function() {        
    $(this).parent().parent().remove();
});
noah
thanks, it wors
loviji
but i have a problem. In my initial table a can remove. but I can't remove rows, if they dynamically added? is it normal?
loviji
+3  A: 

Try this for current and future rows:

$('input:checkbox').live('click',function() {        
  $(this).closest('tr').remove();
});
Nick Craver