I'm struggling to understand how to disable the remaining checkboxes after two are selected and change the border color of the "checkbox_group" to red. Can someone help me with this?
Here is the JavaScript code I have so far:
$(document).ready(function() {
$(".cbox").on("click", function(){
var numberOfChecked = $('input.cbox:checkbox:checked').length;
if (numberOfChecked === 3){
$(this).prop('checked', false);
$("#checkbox_group").css({"border-color":"red"});
} else {
$("#checkbox_group").css({"border-color":"black"});
}
//console.log(numberOfChecked); // debugging
});
});
The current styling for the checkbox group is:
#checkbox_group{
border: solid black 1px;
}
Here is the HTML structure for the checkboxes:
<div id="checkbox_group">
<label>Sports</label>
<input type="checkbox" class="cbox" name="Sports" value="Sports" ><br>
<label>News</label>
<input type="checkbox" class="cbox" name="News" value="News" ><br>
<label>Entertainment</label
><input type="checkbox" class="cbox" name="Entertainment" value="Entertainment" ><br>
<label>Music</label>
<input type="checkbox" class="cbox" name="Music" value="Music" >
</div>