This is the code :
$('#checkBoxContact1').click(function(e) {
e.preventDefault();
if ($('#chbBox1').attr('checked') == true)
$('#chbBox1').attr('checked', 'false');
else $('#chbBox1').attr('checked', 'true');
});
I call this when I click on a link. But in fact seems that it doesnt works…
maybe I should use :checked?
Use
.prop()and more important, do not quote boolean values.For boolean attributes the pure existence matters.
checked="",checked="no",checked="false"all result in the element being checked.To un-check an element through the attribute you’d have to use
.removeAttr('checked').However, you can use the property which is an actual boolean. So
.prop('checked', true_or_false)will do what you want. Actually you could even use.attr('checked', true_of_false)since jQuery 1.6.1 but using.prop()instead of.attr()is a bit faster since it doesn’t need to check if it’s actually a property you are trying to set instead of an attribute.