Check checkbox with tr element

To check a checkbox after clicking a table’s tr element, do the following:

$(document).on("click",".your-tr-element",function(event){
  checkbox = $(this).find("input:checkbox");
  if(event.target.type!="checkbox"){
    if($(checkbox).prop("checked") == true){
      $(checkbox).prop("checked",false);
    }else{
      $(checkbox).prop("checked",true);
    }
  }
});

 
By retaining the event in the callback function, we’re able to ensure the clicked element is not the checkbox itself. This will solve the issue of effectively clicking the checkbox twice and reverting the intended functionality.

Leave a Reply

Your email address will not be published. Required fields are marked *