I have a problem with unchecking a checkbox
. Have a look at my jsFiddle, where I am attempting:
$(\"#check2\").attr(\"checked\", true);
<
$("#chkBox").attr('checked', false);
This worked for me, this will uncheck the check box. In the same way we can use
$("#chkBox").attr('checked', true);
to check the checkbox.
$('#check1').prop('checked', true).uniform();
$('#check1').prop('checked', false).uniform();
This worked for me.
First of all, checked
can have a value of checked
, or an empty string.
$("input:checkbox").uniform();
$('#check1').live('click', function() {
$('#check2').attr('checked', 'checked').uniform();
});
checkbox that act like radio btn
$(".checkgroup").live('change',function() {
var previous=this.checked;
$(".checkgroup).attr("checked", false);
$(this).attr("checked", previous);
});
A simpler solution is to do this rather than using uniform:
$('#check1').prop('checked', true); // will check the checkbox with id check1
$('#check1').prop('checked', false); // will uncheck the checkbox with id check1
This will not trigger any click action defined.
You can also use:
$('#check1').click(); //
This will toggle the check/uncheck for the checkbox but this will also trigger any click action you have defined. So be careful.
EDIT: jQuery 1.6+ uses prop()
not attr()
for checkboxes checked value
In some case you can use this:
$('.myInput').get(0).checked = true
For toggle you can use if else with function