26
Nov
Learn how to check a checkbox using jQuery
Think you need to check a checkbox using jQuery.
If jQuery 1.6+
Use the new .prop() function:
To set
$('.yourCheckbox').prop('checked', true); $('.yourCheckbox').prop('checked', false);
To unset
$('.yourCheckbox').prop('checked', false);
if jQuery 1.5 and below
The .prop() function is not available on jQuery 1.5 and below, so you need to use .attr().
To set
$('.yourCheckbox').attr('checked','checked');
To unset
$('.yourCheckbox').attr('checked','');
or
$('.yourCheckbox').removeAttr('checked');