39

I am using Bootstrap iCheck plugin. How can i find out Whether a check box is checked or not by pressing a button using jquery

$(button).click(function(){

  ckb = $("#ickb").(isChecked);
});
user3316523
  • 630
  • 3
  • 10
  • 14
  • 1
    Starting jquery 1.6 there have been significant changes the way attributes and properties are dealt with. For your case $('#ickb').prop("checked") should do the trick. This statement will simply return true or false depending upon the checked/unchecked state of the check box. For more details refer to attributes vs. properties section on [this](http://api.jquery.com/prop/) link. – RBT Feb 12 '16 at 18:36

2 Answers2

73

Try to use .is() function along with :checked selector to accomplish your task,

ckb = $("#ickb").is(':checked');
Balachandran
  • 9,567
  • 1
  • 16
  • 26
20

Use is() with :checked to get the result as boolean that is true if checkbox is checked.

ckb = $("#ickb").is(':checked');

Or, you can use length, if it is zero then it is not checked.

ckb = $("#ickb:checked").length
Donny V.
  • 22,248
  • 13
  • 65
  • 79
Adil
  • 146,340
  • 25
  • 209
  • 204