I have downloaded a theme with a preconstructed switch component that replaces the normal checkbox functionality. This switch fits in nicely with the UI and I'm desperately trying to make it work but I'm unable to get the 'checked' status of the underlying checkbox to change on a click/touch event.
This is the html structure:
<div class="switch has-switch" data-off-label="<i class='fa fa-times'></i>" data-on-label="<i class='fa fa-check'></i>">
<div class="switch-off switch-animate">
<input checked type="checkbox">
<span class="switch-left"><i class="fa fa-check"></i></span>
<label> </label>
<span class="switch-right"><i class="fa fa-times"></i></span>
</div>
</div>
The switch functionality works perfectly fine, but I'm unable to get it to toggle the 'checked' value of the checkbox input attribute.
I've tried a few solutions. The last one I've tried is this (Note this was a test to see whether I could at least get it to uncheck when clicked):
$(function () {
$('.switch').click(function() {
console.log(this);
var CheckboxInput = $(this).find('input[type="checkbox"]');
if ($(CheckboxInput).is(':checked')) {
CheckboxInput.prop('checked', false);
}
}
});
});
My javascript knowledge is not great (more of a rails guy). Could anybody please help me find what I'm doing incorrectly?