checkbox in jquery code example

Example 1: How to check whether a checkbox is checked in jQuery?

//using plane javascript 
if(document.getElementById('on_or_off_checkbox').checked) {
    //I am checked
} 

//using jQuery
if($('#on_or_off_checkbox').is(':checked')){
    //I am checked
}

Example 2: jquery check checkbox

$('.myCheckbox').prop('checked', true);
$('.myCheckbox').prop('checked', false);

Example 3: jquery checkbox checked

$("checkbox").is(":checked")

Example 4: checkbox click event jquery

$('input[type="checkbox"]').click(function(){
  if($(this).is(":checked")){
    //input element where you put value
    $("#isClicked").val("Yes");
    // console.log($("#isClicked").val());              
  }
  else if($(this).is(":not(:checked)")){
    $("#isClicked").val("");
    //  console.log( $("#isClicked").val());
  }
});

Example 5: checkbox on click jquery

$(document).ready(function() {
  //set initial state.
  $('#textbox1').val($(this).is(':checked'));

  $('#checkbox1').change(function() {
    $('#textbox1').val($(this).is(':checked'));
  });

  $('#checkbox1').click(function() {
    if (!$(this).is(':checked')) {
      return confirm("Are you sure?");
    }
  });
});

Example 6: how to check the checkbox in jquery

check all checkbox whit button

// Check #x
$( "#x" ).prop( "checked", true );
 
// Uncheck #x
$( "#x" ).prop( "checked", false );


example

      $('.checkAll').click(function () {
                if($(':checkbox').is(':checked')){
                    $(':checkbox').prop( "checked", false );
                }else{
                    $(':checkbox').prop( "checked", true );
                }
            })