1$('.myCheckbox').prop('checked', true);
2$('.myCheckbox').prop('checked', false);
1$( "SELECTOR" ).attr( "checked" ) // Returns ‘true’ if present on the element, returns undefined if not present
2$( "SELECTOR" ).prop( "checked" ) // Returns true if checked, false if unchecked.
3$( "SELECTOR" ).is( ":checked" ) // Returns true if checked, false if unchecked.
1//jQuery 1.6+ use:
2$('.checkboxClass').prop('checked', true);
3//jQuery 1.5.x and below use:
4$('.checkboxClass').attr('checked', true);
1$(document).ready(function() {
2 //set initial state.
3 $('#textbox1').val($(this).is(':checked'));
4
5 $('#checkbox1').change(function() {
6 if($(this).is(":checked")) {
7 var returnVal = confirm("Are you sure?");
8 $(this).attr("checked", returnVal);
9 }
10 $('#textbox1').val($(this).is(':checked'));
11 });
12});
1if($("#isAgeSelected").is(':checked'))
2 $("#txtAge").show(); // checked
3else
4 $("#txtAge").hide(); // unchecked
5