SO - 19164816

by Arun P Johny

HTML

<table>
    <tr>
        <th>
            <input type="checkbox" id="selectAll" />
        </th>
        <th>hi!</th>
    </tr>
    <tr>
        <td>
            <input type="checkbox" id="1" />
        </td>
        <td>hi!</td>
    </tr>
    <tr>
        <td>
            <input type="checkbox" id="2" />
        </td>
        <td>hi!</td>
    </tr>
</table>

JavaScript

$('#selectAll').click(function (e) {
    $(this).closest('table').find('td input:checkbox').prop('checked', this.checked);
});