How to check if a checkbox is checked using jQuery?
Hi everyone! I just started learning jQuery and came across this task: I need to check if a checkbox on the page is checked, and depending on that, perform some action. I wrote this code, but for some reason it doesn't work:
```javascript
if ($('#myCheckbox').val() == 'checked') {
alert('Checkbox is checked');
}
```
When I run it, the alert doesn't appear, even if the checkbox is checked. I also tried using `$('#myCheckbox:checked')` — but then the alert always fires, regardless of the state. Please tell me how to do this correctly? I need it specifically in jQuery, without plain JavaScript. Preferably with examples for different versions of jQuery.
Here is my HTML:
```html
Accept terms
```
No answers yet.
Log in to leave an answer
Blogs