How to Uncheck Checkbox in jQuery
To uncheck a checkbox in jQuery, use the .prop()
function. Pass checked as the first argument (the attribute) and false as the second argument.
Uncheck Checkbox with prop() Function Example
Let's demonstrate this with an example using a checkbox with a particular ID.
<input type="checkbox" name="foo" id="foo" checked>
$('#foo').prop('checked', false);
Here is another example, this time unchecking all checkbox elements with a particular class.
$('.foo').prop('checked', false);
It's simply the case of calling classes with the .
(dot) selector and jQuery will handle the rest.
Use the removeAttr() jQuery Function to Uncheck Check
Another option is to remove the checked attribute completely using the jQuery removeAttr()
function. Here is an example demonstrating this:
$('#foo').removeAttr('checked');