27th July 2009 - 2 minutes read time
To check and uncheck a checkbox using jQuery you first need to access the checkbox element using the $() function. Once you have done that you can retrieve or change the value of the checkbox quite easily.
To uncheck a checkbox use the following snippet, which makes nice use of the jQuery attribute filters:
$('input[name=mycheckbox]').attr('checked', false);
To check a checkbox use the following:
$('input[name=mycheckbox]').attr('checked', true);
To test if a checkbox is set or not use one of the following, both return true if checked and false is unchecked.
var checked = $('input[name=mycheckbox]').is(':checked');
var checked = $('input[name=mycheckbox]').attr('checked');