Setting "checked" for a checkbox with jQuery

Setting "checked" for a checkbox with jQuery

To check a checkbox using jQuery, you can use the prop() method to set the checked property to true. Here's an example:

// Assuming the checkbox has an ID of "myCheckbox"
$('#myCheckbox').prop('checked', true);

This will set the checked property of the checkbox to true, which will cause it to become checked in the UI.

Note that if you want to uncheck the checkbox, you can set the checked property to false:
$('#myCheckbox').prop('checked', false);

This will uncheck the checkbox.



Back to The Programmer Blog