Avatar ·

How to set or unset the checked flag of a checkbox using jQuery?

Hello, colleagues! I'm a beginner in JavaScript and jQuery. I have a simple form with several checkboxes. I want to programmatically set or unset the "checked" flag for a specific element using jQuery. Let's say I have this HTML: ```html ``` I've tried different approaches, but they don't work as I expect. For example, I tried: ```javascript $('#myCheckbox').attr('checked', true); // Seems to work, but not always $('#myCheckbox').prop('checked', true); // I heard this is more correct, but I don't understand the difference $('#myCheckbox').click(); // ```