Page 1 of 1

Check and Uncheck a checkbox with jQuery

Posted: 10 Jan 2015, 07:38
by MarPlo
I want to do something like this:

Code: Select all

$(".chkox").checked(true);
Or:

Code: Select all

$(".chkox").selected(false);
I wish to set the "checked" value to check or uncheck the checkboxes with class="chkbox".
How can I do it with jQuery?

Check and Uncheck a checkbox with jQuery

Posted: 10 Jan 2015, 07:54
by Admin
Use the prop() method.

Code: Select all

$('.chkbox').prop('checked', true);  // checking
$('.chkox').prop('checked', false);  // unchecking
And if you want to check if a checkbox is checked or not, use this code:

Code: Select all

if($('#chk_id').is(':checked')) {
  // checkbox checked
}
else {
  // checkbox unchecked
}