Try giving a class to your checkboxes :
<input type="checkbox" class="cls1" id="example1" value="1">
<input type="checkbox" class="cls1" id="example2" value="2">
Then, when binding the mousedown
event, instead of selecting them by their id, select them with that class :
$('.cls1').mousedown(function() {
if (!$(this).is(':checked')) {
this.checked = confirm("Are you sure?");
$(this).trigger("change");
}
});
This is to stay as close as possible from your original code, which may not be the best. Without a broader view on it it's hard to tell. Note that in the case you're adding dynamically the checkboxes clientside (which is not the case I presume cause you talk about generating it with PhP) you would need a different selector in order to use what is called delegated events