I have a series of checkboxes that I want to make a little more mobile-friendly so I'm hiding the checkbox and using labels as buttons. What I want to do is give the user feedback by changing the color of the label from yellow to green when they tap, and then back to yellow when tapping again. I'm pulling my hair out trying to understand why what I'm using isn't working.
<div id="div">
<label for="checkbox" id="label1" class="bg-warning text-center pointer" style="width:100px; padding:8px">
<input type="checkbox" name="checkbox1" id="checkbox1" value="checked1" style="display:none">test
</label>
</div>
<label for="checkbox" id="label2" class="bg-warning text-center pointer" style="width:100px; padding:8px">
<input type="checkbox" name="checkbox2" id="checkbox2" value="checked2" style="display:none">test
</label>
</div>
</div>
<script>
$(document).ready(function(){
$('#div').on('click', function(e) {
$('#div').each( function( index, element) {
var el = $(element);
if($(el).hasClass('bg-warning')) {
$(el).removeClass('bg-warning').addClass('bg-success');
} else {
$(el).removeClass('bg-success').addClass('bg-warning');
}
});
});
});
</script>