1

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/

3
  • 1
    The whole thing can be written $('.showStatewide input').on("click",function () { $('.showRegion input').prop('checked', this.checked);}); Commented Feb 18, 2014 at 20:55
  • attri - use with values in html on page load. prop - use when an element's 'state' is modified via js for example. Commented Feb 18, 2014 at 20:57
  • mplungjan - I'm aware that that is a shorter version. But temp variables make it easier to troubleshoot problems. Commented Feb 18, 2014 at 21:43

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

From 1.8 onwards, the best is prop. +1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.