So I have dynamically created checkboxes that share the same class:
<input type="checkbox" class="boxes" />
<input type="checkbox" class="boxes" />
And have a few dropdown options that share that same class also:
<select class = "needToDisable">
<option value="volvo">Volvo</option>
</select>
As these are generated dynamically, I went for this approach to check if the length of the checked checkboxes is > 0. If so disable all dropdowns with the class "needToDisable"
$(".boxes").on('click',function(){
if ($('.boxes:checked').length > 0) {
$(".boxes").prop("disabled", true);
} else {
$(".boxes").prop("disabled", false);
}
});
I have seen a few other examples like:
Using jquery to get all checked checkboxes with a certain class name
But it says "click" is not defined, I don't think I can use in this way.