[jQuery] Click on checkbox, unexpected double event
I have a set of checkboxes and some JavaScript code to handle when the
user clicks on them. In the code below, there are functions for
selecting and deselecting a checkbox, and then there's a function to
handle event binding. And there's the $(document).ready() binding.
In Firefox when I click on a checkbox, the alert comes up as expected.
Then when I dismiss it, the alert comes up again. I added
event.stopPropagation() and return false to the select / deselect
functions but it makes no difference. Two alerts.
If anyone can shed light on this I would appreciate it.
Thanks,
Ethan
function selectList(event) {
alert('Selecting the list.');
}
function deselectList(event) {
alert('Deselecting the list.');
}
function bindEvents() {
$('input.list_checkbox').click(function(event) {
if ($(event.target).is(':checked')) {
selectList(event);
} else {
deselectList(event);
}
});
}
$(document).ready(function() {
bindEvents();
});