mardi 6 décembre 2016

onchange event on one checkbox in a group

I have a group of checkboxes as -

<input id="check_1" name="check[1]" type="checkbox" value="1"/>
<label for="check_1">One</label>&nbsp;

<input id="check_2" name="check[2]" type="checkbox" value="1"/>
<label for="check_2">Two</label>&nbsp;

<input id="check_3" name="check[3]" type="checkbox" value="1"/>
<label for="check_3">Three</label>

Due to variable values of id and name, I'm unable to handle onclick event on checkbox with label One.

I've tried this which works fine, but I don't want to use check_1 since the number 1 is variable and could be changed.

$("#check_1").change(function() {
  alert('Checkbox One is clicked');
});

How do I do this as I have no access to modify the html ?




Aucun commentaire:

Enregistrer un commentaire