I want some elements to have a class applied to them if a checkbox is checked, and to have the class removed if they are not checked (or un-checked). I've tried writing this a few different ways but I'm only ever able to give apply the class to the elements once the checkbox is clicked, but re-clicking doesn't remove the class from the elements even though I expect it would.
jQuery(document).ready(function($) {
$('input[type="checkbox"]').on("click", function() {
if($('#filter-item.Acting').prop('checked') == true) {
$('.filter-Acting').addClass("hidden");
} else if ($('#filter-item.Acting').prop('checked') == false) {
$('.filter-Acting').removeClass("hidden");
}
}
});
What's the easiest way to accomplish what I'm after? Thanks.
Aucun commentaire:
Enregistrer un commentaire