Jquery Check all checkbox

Cindy93

Why does my check all button work once and doesn't work at 3rd click. the check all button only works at firts click. I check the dom and its updating but the view does. What is the cause of the problem?

FIDDLE

jQuery('.sp_country').click(function () {
    var checkbox = $(this).find(":checkbox"),
        checked = checkbox.is(":checked");
    checkbox.prop("checked", !checked);

});

jQuery('.sp_country input:checkbox').on('click', function (e) {
    e.stopImmediatePropagation();
    var checked = (e.currentTarget.checked) ? false : true;
    e.currentTarget.checked = (checked) ? false : checked.toString();
});

jQuery('#bt_checkbox').click(function (e) {
    e.stopImmediatePropagation();
    if (jQuery(this).val() === 'Uncheck All') {
        jQuery('#country input:checkbox').removeAttr('checked');
        jQuery(this).val('Check All');
    } else {
        jQuery('#country input:checkbox').attr('checked', 'checked');
        jQuery(this).val('Uncheck All');
    }
});
Tushar Gupta - curioustushar

fiddle Demo

Change

jQuery('#country input:checkbox').attr('checked', 'checked');

to

jQuery('#country input:checkbox').prop('checked', true);


Use .prop()

Read .prop() vs .attr()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Jquery Check all checkbox

From Dev

jQuery filter, check all checkbox values

From Dev

jquery check all input:checkbox on button click

From Dev

check all jquery not working for dynamically populated checkbox

From Dev

Check all with specific value in checkbox using jquery

From Dev

jQuery / JavaScript: Check all checkboxes and Check each checkbox to display div

From Dev

Check if a checkbox is check in jQuery

From Dev

Uncheck a "Check all" Checkbox

From Dev

Check/uncheck all checkbox

From Dev

jQuery - Unchecked other checkbox when CHECK ALL is checked

From Dev

jQuery: establishing a relation between check-all checkbox and the child checkboxes

From Dev

Call jQuery function for each checkbox on Check/Uncheck All

From Dev

Checkbox & Check all function in Datatable Jquery PHP Mysql

From Dev

How to implement Jquery checkbox check all/uncheck all function with a checkbox in a loop?

From Java

Check if checkbox is checked with jQuery

From Dev

check a checkbox with jQuery?

From Dev

Check Checkbox in jquery

From Dev

Check/Uncheck checkbox jQuery

From Dev

Check the parent checkbox with . jQuery

From Dev

Check multiple Checkbox jQuery

From Dev

JQuery: Checkbox how to check or uncheck all checkboxes when another checkbox is selected

From Dev

jquery checkbox select all

From Dev

ListView with CheckBox, Check all checkbox does the opposite

From Dev

How to check if all of the checkbox are checked

From Dev

Angular 2 checkbox check all

From Dev

Auto check/uncheck the "All" checkbox

From Dev

how to check if all checkbox is unchecked

From Java

check / uncheck checkbox using jquery?

From Dev

Jquery checkbox check and uncheck on hover

Related Related

HotTag

Archive