How To Check And Uncheck A Checkbox With jQuery

27th July 2009 - 1 minute 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.

  1. var checked = $('input[name=mycheckbox]').is(':checked');
  2. var checked = $('input[name=mycheckbox]').attr('checked');

Add new comment

The content of this field is kept private and will not be shown publicly.