Last active
December 2, 2018 12:59
-
-
Save ricardobrg/89b183091bf34223c0e0df375a8ee1a7 to your computer and use it in GitHub Desktop.
jQuery checkboxes handling based on ids and classes with indeterminate property
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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