checkbox when checked check all checkboxes code example

Example 1: checkbox on click jquery select all

$("#checkAll").click(function(){
    $('input:checkbox').not(this).prop('checked', this.checked);
});

Example 2: when i click on one checkbox check all checkboxes

function setAllCheckboxes(divId, sourceCheckbox) {
    divElement = document.getElementById(divId);
    inputElements = divElement.getElementsByTagName('input');
    for (i = 0; i < inputElements.length; i++) {
        if (inputElements[i].type != 'checkbox')
            continue;
        inputElements[i].checked = sourceCheckbox.checked;
    }
}

Tags:

Html Example