How to check if checkbox is checked in jQuery?

checkbox is checked

There are many ways to check if a checkbox is checked or not:
Using Prop:

if($('#checkMeOut').prop('checked')) {
    // something when checked
} else {
    // something else when not
}

Using is() Method:

$('#checkMeOut').is(":checked");

Using attribute selector:

$('input[type=checkbox]:checked')

Using click action:

$('#checkMeOut').click(function() {
  if (this.checked) {
    console.log('checked');
  } else {
    console.log('un-checked');
  }
});

Using checked attribute:

if($("#checkMeOut").attr('checked') == true){
  alert("checked=true");
}

You can get more details about this topic from here.
To get to know more about other JQuery topics, you can check these articles too.

Please follow and like us:

Related Posts

Leave a Reply

Share