select one checkbox with jquery

Subject:

Originally this snippet was coded with .attr instead of .prop which cause a problem.

    $("#myform input:checkbox").change(function() {    $("#myform input:checkbox").prop("checked", false);    $(this).prop("checked", true);

 

For more information see $.prop - Attributed vs Properties

Specifically:

...the most important concept to remember about the checked attribute is that it does not correspond to the checked property. The attribute actually corresponds to the defaultChecked property and should be used only to set the initial value of the checkbox. The checked attribute value does not change with the state of the checkbox, while the checked property does.

2015-01-23 15:40:57gstlouis