I have custom checkboxes:
<p>
<input class="preventUncheck" id="toggle-on1" type="checkbox">
<label for="toggle-on1">Selling</label>
</p>
<p>
<input class="preventUncheck" id="toggle-on2" type="checkbox">
<label for="toggle-on2">Rent</label>
</p>
$(function() {
//prevent to uncheck all checkboxes
$('.preventUncheck').on('change', function() {
$('.preventUncheck').length == 0
&& !this.checked
&& $(this).prop('checked', true);
});
});
I want to prevent unchecking all checkbox, that means alway one checkbox should be checked and if user try to unchecking it, javascript prevent to do it.
How can i do this work?