photo_tom
photo_tom

Reputation: 7342

Unable Set Checkbox to Checked in Chrome using jQuery

I have some code that is broken in the latest version of chrome (32.0.1700.107). jQuery version is 1.10.1. This code has been running in other browsers for the last year. It does work correctly in IE8. The key section of code is below -

var stateWideCb = $('.showStatewide input');
stateWideCb.change(function () {
    var b = $(this).is(':checked');
            $('.showRegion input').attr('checked', b);
    });

What happens is that after the first two clicks on the the Master checkbox, the code stops working.

You can see it at http://jsfiddle.net/photo_tom/dXczB/1/

Upvotes: 1

Views: 1107

Answers (1)

j08691
j08691

Reputation: 207861

Change:

.attr('checked', b);

to

.prop('checked', b);

jsFiddle example

As the jQuery docs on .attr() state:

To retrieve and change DOM properties such as the checked, selected, or disabled state of form elements, use the .prop() method.

Upvotes: 4

Related Questions