codingtcher.com
Theme Night
Home
Login

Jquery checkbox event change

//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());
  }
});

//jQuery checkbox changed event
$("#myCheckBoxID").change(function() {
    if(this.checked) {
        //I am checked
    }else{
        //I'm not checked
    }
});

//change checkbox jquery alert
$('#checkbox1').mousedown(function() {
    if (!$(this).is(':checked')) {
        this.checked = confirm("Are you sure?");
        $(this).trigger("change");
    }
});

//jquery watch checkbox change
$('input[type="checkbox"]').change(function() {
    alert ("The element with id " + this.id + " changed.");
});

Related Code