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
  • 5,376
  • 15
  • 56
  • 115
  • 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
  • 158,678
  • 38
  • 247
  • 274
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,512
  • 5
  • 32
  • 55
0

you can simply do this,

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

to see if a checkbox is checked or not:

$('#isWorking').is(':checked');
dev1234
  • 5,376
  • 15
  • 56
  • 115
0

You can use jquery attr

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

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

Krish R
  • 22,583
  • 7
  • 50
  • 59
0

Use .prop()

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

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

Community
  • 1
  • 1
Satpal
  • 132,252
  • 13
  • 159
  • 168
0

Use this:

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

Hope it helps.

MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
0
$("#isWorking").attr('checked', true);
HDT
  • 2,017
  • 20
  • 32