Ask questions and get good answers on mb.jQuery.components

How to check and uncheck a checkbox with jQuery and how do I know if a checkbox is checked ?

asked Nov 04 '09 at 11:07

Federico%20Soldani's gravatar image

Federico Soldani
173128

edited Nov 04 '09 at 22:47

Matteo%20Bicocchi's gravatar image

Matteo Bicocchi ♦♦
1776129


to check/uncheck:

// applied to all checkbox of a form:    
 $("#MyFormID input[type='checkbox']").each(function(){
      $(this).attr('checked', $(this).is(':checked')); 
  });

//applied to a specific checkbox of a form:
$("#MyCheckboxID").attr('checked', $("#MyCheckboxID").is(':checked'));

to know if the checkbox is checked:

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

answered Nov 04 '09 at 11:33

Matteo%20Bicocchi's gravatar image

Matteo Bicocchi ♦♦
1776129

For live Demo click this below link: http://jsfiddle.net/nanoquantumtech/FgGxg/

<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { $('#btnSubmit').click(function () { var checkBoxCheckedCount = $('#MyFormID').find('[type="checkbox"]:checked').length; $('#Result').html(checkBoxCheckedCount > 0 ? checkBoxCheckedCount + ' Check Box Is Checked' : 'All Check Box Is UnChecked'); }); }); </script> </head> <body>
<input type="checkbox"/>Car
<input type="checkbox"/>Van
<input type="checkbox"/>Bus
<input type="button" id="btnSubmit" value="Submit"/> </body> </html>

answered Apr 18 at 05:59

ThulasiRam's gravatar image

ThulasiRam
11

edited Apr 18 at 06:03

http://jsfiddle.net/nanoquantumtech/FgGxg/

(Apr 18 at 06:03) ThulasiRam
Your answer
toggle preview

jQuery main site - Matteo Bicocchi