Check if checkbox input is checked using jQuery

We used .attr() method to get the attribute value of a checkbox. Which would return “checked” if the checkbox state is checked. But as of jQuery 1.6 it will return undefined if checkbox state is not set.

Therefore, if you are still using previous jQuery, you can check state of checkbox input like so :

1
2
3
4
5
//traditional way, before jQuery 1.6
var is_checked = $('#mycheckbox').attr("checked");    
if(is_checked == "checked"){
    //do stuff
}

jQuery 1.6+

Those of you using jQuery 1.6+, you can use .prop() method instead to find-out checkbox state, which returns true or false.

1
2
3
4
var is_checked = $('#mycheckbox').prop('checked');  
if(is_checked){
    //do something
}
1
  • Saran

  • Article written by Saran. Saran Chamling loves the web technology, and enjoys designing, exploring and writing about it @sanwebe.com. You can find him at Twitter, Google or Facebook.