I recommend that you add a container and immediately select all the checkboxes.
As for your question, the event signature is incorrect, then the correct function(e){} . In addition, you should check if the item is checked, and not click.
$("#chk").change(function(e){ if ($(this).is(":checked")) alert("checked"); else alert("not checked"); });
To make it easier, use a container
HTML example
<div id="checks"> <input type="checkbox" id="chk1" /> <input type="checkbox" id="chk2" /> <input type="checkbox" id="chk3" /> <input type="checkbox" id="chk4" /> </div>
And for ratings, I prefer to set data on elements, for example:
$("#chk1").data("Score", 3); $("#chk2").data("Score", 1); $("#chk3").data("Score", 2); $("#chk4").data("Score", 5); $("#checks :checkbox").change(function(e){ if ($(this).is(":checked")) alert("checked Score: " + $(this).data("Score")); else alert("not checked Score: " + $(this).data("Score")); });
Brunolm
source share