Skip to content

Instantly share code, notes, and snippets.

@ricardobrg
Last active December 2, 2018 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricardobrg/89b183091bf34223c0e0df375a8ee1a7 to your computer and use it in GitHub Desktop.
Save ricardobrg/89b183091bf34223c0e0df375a8ee1a7 to your computer and use it in GitHub Desktop.
jQuery checkboxes handling based on ids and classes with indeterminate property
jQuery(document).ready(function($){
$(":checkbox").click(function(){
let isChecked = $(this).prop('checked');
let id = $(this)[0].id;
let itemClasses = $(this).attr('class');
if (id != undefined && id != ""){
$("."+id).prop('checked',isChecked);
}
if (!isChecked){
if (itemClasses != undefined){
let classList = itemClasses.split(/\s+/);
$.each(classList, function(index, item){
console.log(item);
if (item != ""){
$("#"+item).prop("indeterminate", true);
$("#"+item).val("i");
}
});
}
}
$(this).val(isChecked);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment