SO - 23365215

by Arun P Johny

HTML

<table>
    <tr class="ui-grid groupHead">
        <td>
            <input type="checkbox" class="groupHeadCheck" />
        </td>
    </tr>
    <tr>
        <td>
            <input type="checkbox" id="1" />
        </td>
    </tr>
    <tr>
        <td>
            <input type="checkbox" id="2" />
        </td>
    </tr>
    <tr>
        <td>
            <input type="checkbox" id="3" />
        </td>
    </tr>
    <tr class="ui-grid groupHead">
        <td>
            <input type="checkbox" class="groupHeadCheck" />
        </td>
    </tr>
    <tr>
        <td>
            <input type="checkbox" id="4" />
        </td>
    </tr>
</table>

JavaScript

$(function ($) {
    $(".groupHeadCheck").on("click", function (event) {
        $(this).closest('tr').nextUntil('tr.groupHead').find('input[type="checkbox"]').prop('checked', this.checked)
    })
});