Skip to content

Instantly share code, notes, and snippets.

@jakobhans
Last active September 23, 2020 01:22
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 jakobhans/b81caa1e688996d0079790ee1fc59394 to your computer and use it in GitHub Desktop.
Save jakobhans/b81caa1e688996d0079790ee1fc59394 to your computer and use it in GitHub Desktop.
jQuery('input[type="checkbox"]').change(function() {
jQuery('#noMatchedCommunities').hide();
jQuery('.matchedCommunity').removeClass('matchedCommunity');
let checkedBoxes = jQuery('input[type="checkbox"]:checked').length;
if (checkedBoxes === 0) {
jQuery('ul.matches li').show();
} else {
jQuery('ul.matches li').hide();
jQuery('ul.matches li').each(function() {
let matches = true;
const communityPointer = this;
jQuery('input[type="checkbox"]:checked').each(function() {
console.log(jQuery(communityPointer).attr('class') + ' / ' + jQuery(this).attr('id'));
if (!jQuery(communityPointer).hasClass(jQuery(this).attr('id'))) {
matches = false;
}
});
if (matches) {
jQuery(this).addClass('matchedCommunity');
jQuery(this).show();
}
});
if (jQuery('.matchedCommunity').length === 0) {
jQuery('#noMatchedCommunities').show();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment