But that only handles one checkbox and doesn't work if I have more
than one like above.
That is because when using the id selector, jQuery only returns the first element it finds.
Ids should be unique.
As per documentation :
Each id value must be used only once within a document. If more than
one element has been assigned the same ID, queries that use that ID
will only select the first matched element in the DOM. This behavior
should not be relied on, however; a document with more than one
element using the same ID is invalid.
If you need to group elements you can either assign a class:
<input type="checkbox" id="check1" class="checkbox-group1">
<input type="checkbox" id="check2" class="checkbox-group1">
<input type="checkbox" id="check3" class="checkbox-group1">
...attaching the click event selecting by class:
$('.checkbox-group1').click(function(){...})
or you can use data attributes:
<input type="checkbox" id="check1" data-group="checkbox-group1">
<input type="checkbox" id="check2" data-group="checkbox-group1">
<input type="checkbox" id="check3" data-group="checkbox-group1">
...attaching the click event selecting by data attribute:
$('input[data-group="checkbox-group1"]').click(function(){...})