I want to validate that at least one checkbox of a group is selected, but I don't know their ids or names since they are dynamic, they change. What if is the name or id of the div that encompasses them. I can do it?
<div class="group-check1">
<input type="checkbox"> Opc 1
<input type="checkbox"> Opc 2
<input type="checkbox"> Opc 3
</div>
I have two groups of checkboxes, independent, in both there must be at least 1 check selected.
As @aloMalbarez points out, to verify if one is ckecked, it would only be necessary with the selector:
If, in addition, some other condition had to be verified, in addition to the mere existence, using
querySelectorAll(".group-check1 input")
together withsome()
would be usefulIt is necessary to clarify that at the moment of writing this, with a selector we can verify if an attribute exists or not in time, but if it had a value, only its initial value. If we wanted to make a selector to check a certain value of
value
for example oneinput type='text'
, we could just make a selector to check the initial value, but not its changes. In the case of the checkbox we can do it because we verify if the attribute exists or not, not the value.