You can set the "checked" attribute of a checkbox using the .prop() method in jQuery:
$('.myCheckBox').prop('checked', true);
If you're working with jQuery versions prior to 1.6, you can use the .attr() method instead:
$('.myCheckBox').attr('checked', true);
You can also use the underlying HTMLInputElement to modify the .checked property:
$('.myCheckBox')[0].checked = true;
One should use .prop() and .attr() methods instead of this as they will operate on all matched elements.
The above is the detailed content of How Do I Programmatically Check a Checkbox with jQuery?. For more information, please follow other related articles on the PHP Chinese website!