JSFiddle - React, Tailwind, and code Playground
HTML
<div class="tags">
<label><input type="checkbox" class="arts" /> Arts </label>
<label><input type="checkbox" class="computers" /> Computers </label>
<label><input type="checkbox" class="health" /> Health </label>
<label><input type="checkbox" class="video-games" /> Video Games </label>
</div>
Then on the page there will be results and each result has tags attached to it.
<ul class="results">
<li class="arts computers">
Result 1
</li>
<li class="video-games">
Result 2
</li>
<li class="computers health video-games">
Result 3
</li>
<li class="arts video-games">
Result 4
</li>
</ul>
JavaScript
$('.tags')
.on('update', function() {
// Limit the selector(s) to search for:
var $filters = $(this).find('input:checked');
// Get the class names of interest
// Return null (rather than "") to keep them out of the result array
var $classes = $filters.map(function(){ return this.className || null; });
// Use .replace() if your checkboxes might target multiple classes
var selector = $classes.get().join('.').replace(/ /g,'.');
var $results = $('ul.results > li').hide();
if (selector)
$results.filter('.'+selector).show();
})
// Relay any changes to the display-state container (.tags)
.on('change','input[type="checkbox"]',function() {
$(event.currentTarget).trigger('update');
})
// When first loaded, apply the server-supplied checkbox state(s) to the page:
.trigger('update');