
Validate using JQuery if a checkbox is checked
If you are writing a JQuery code, and you need to add some validations working with checkboxes, the following snippet would help you.
Checkbox:
1 |
<input id="mychk" type="checkbox" /> |
JQuery code to validate if it is checked:
1 2 3 4 5 |
if(jQuery('#mychk:checkbox:checked').length > 0) { console.log('Checked'); }else { console.log('Unchecked'); } |