1//using plane javascript
2if(document.getElementById('on_or_off_checkbox').checked) {
3 //I am checked
4}
5
6//using jQuery
7if($('#on_or_off_checkbox').is(':checked')){
8 //I am checked
9}
1$('.myCheckbox').prop('checked', true);
2$('.myCheckbox').prop('checked', false);
1//jQuery 1.6+ use
2$('.checkbox').prop('checked', true); //false for uncheck
3//jQuery 1.5.x and below use
4$('.checkbox').attr('checked', true); //false for uncheck
1// Check a checkbox
2$(selector).prop('checked', true);
3// Un-check a checkbox
4$(selector).prop('checked', false);
5// Determine if checked or not
6isChecked = $(selector).prop('checked');
1check all checkbox whit button
2
3// Check #x
4$( "#x" ).prop( "checked", true );
5
6// Uncheck #x
7$( "#x" ).prop( "checked", false );
8
9
10example
11
12 $('.checkAll').click(function () {
13 if($(':checkbox').is(':checked')){
14 $(':checkbox').prop( "checked", false );
15 }else{
16 $(':checkbox').prop( "checked", true );
17 }
18 })
19