JSFiddle - React, Tailwind, and code Playground
HTML
<div class="choice">
<input id="choice_1" type="checkbox" name="choice_1" value="choice_1" />
<label for="choice_1">Chicago</label>
</div>
<div class="choice">
<input id="choice_2" type="checkbox" name="choice_2" value="choice_2" />
<label for="choice_2">Los Angeles</label>
</div>
<div class="choice">
<input id="choice_3" type="checkbox" name="choice_3" value="choice_3" />
<label for="choice_3">San Francisco</label>
</div>
CSS
.choice input {
display: none;
}
.choice {
border: 1px solid gray;
padding: 30px;
margin: 20px;
}
.active {
background-color: yellow;
}
JavaScript
$(document).ready(function() {
var choices = $('.choice');
choices.on('click', function(event) {
var choice = $(event.target);
var input = choice.find('[type="checkbox"]');
input
.prop('checked', !input.is(':checked'))
.trigger('change');
});
var inputs = $('.choice input');
inputs.on('change', function(event) {
var input = $(event.target);
var choice = $(this).closest('.choice');
if (input.is(':checked')) {
choice.addClass('active');
}
else {
choice.removeClass('active');
}
});
});