2

I am trying to check and uncheck a check box. this is my html code.

<input type="checkbox" id="isWorking" name="isWorking" />

i tried to do it with jquery this way,

$('#isWorking').val('1');
$('#isWorking').val('0');

How can I control checkboxes with jQuery?

dev1234
  • 4,926
  • 13
  • 52
  • 111
  • 1
    possible duplicate of [How do I check a checkbox with jQuery?](http://stackoverflow.com/questions/426258/how-do-i-check-a-checkbox-with-jquery) – dev1234 Dec 25 '13 at 08:49

8 Answers8

3

Use .prop method.

$('#isWorking').prop('checked', true);  // check it
$('#isWorking').prop('checked', false); // uncheck it
xdazz
  • 154,648
  • 35
  • 237
  • 264
1

For set Checkbox value you need to use .prop

$('#isWorking').prop('checked', true);
$('#isWorking').prop('checked', false);

Setting "checked" for a checkbox with jQuery?

Community
  • 1
  • 1
0

Try this out:- http://jsfiddle.net/adiioo7/awJXM/1/

JS:-

$('#isWorking').attr("checked",true);
Aditya Singh
  • 9,431
  • 5
  • 31
  • 54
0

you can simply do this,

$("#isWorking").attr('checked', true);

to see if a checkbox is checked or not:

$('#isWorking').is(':checked');
dev1234
  • 4,926
  • 13
  • 52
  • 111
0

You can use jquery attr

$('#isWorking').attr('checked', true);

Ref: http://api.jquery.com/attr/

Krish R
  • 22,188
  • 7
  • 49
  • 57
0

Use .prop()

 $('#isWorking').prop('checked', true/false);

A good read .prop() vs .attr()

Community
  • 1
  • 1
Satpal
  • 129,808
  • 12
  • 152
  • 166
0

Use this:

$("#isWorking").prop("checked",true); //check
$("#isWorking").prop("checked",false); //uncheck

Hope it helps.

MysticMagicϡ
  • 28,305
  • 16
  • 71
  • 119
0
$("#isWorking").attr('checked', true);
HDT
  • 1,911
  • 18
  • 32