Check and Uncheck a checkbox with jQuery

MarPlo
Posts: 88

Check and Uncheck a checkbox with jQuery

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?

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 }

Similar Topics