jQuery – Detect If a Checkbox is checked or unchecked

This post shows you how to detect if a checkbox control is checked or unchecked by using .is() jQuery method.

 

1. Use the below approach if you need to check the status of the checkbox on page load

if ($('#confirmation-checkbox').is(':checked')) {
    console.log('This checkbox control is checked');
} else {
    console.log('This checkbox control is unchecked');
}

 

2. Use the below approach if you need to check the status of the checkbox on its click event

$('#checkbox-control').on('click', function() {
    if ($(this).is(':checked')) {
        console.log('This checkbox control is checked');
    } else {
        console.log('This checkbox control is unchecked');
    }
});

guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x