How to check if a checkbox is checked using jQuery?
Hi everyone! I just started learning jQuery and ran into a problem. I have a form with a checkbox, and I need to check if the checkbox is checked by the user when submitting the form. I tried several methods, but nothing works as I expected.
Here's my HTML:
```html
I agree to the terms
```
And my jQuery code:
```javascript
$('#submit').click(function() {
if ($('#agree').val() == 'on') {
alert('Checkbox is checked');
} else {
alert('Checkbox is not checked');
}
});
```
When clicking the button, it always outputs "Checkbox is not checked", even if I check the box. I read that checkboxes have a `checked` property, but how do I get it via jQuery? I tried `$
No answers yet.
Log in to leave an answer