I have a set of checkboxes setup in a series of div fieldcontain + fieldset controlgroups. They are grouped by topic with 12 main开发者_运维技巧 topics and 2-5 sub-topic under each.
When I "change" a checkbox, it fires the change event for the entire controlgroup. If I remove the control group fieldset, it fires the change event (when tapped) for the entire list, whether I use input[name="checkbox_name"] or input.checkbox-class.
How do I get the change for just the actual checkbox changed (from unchecked to checked or checked to unchecked)?
Assuming you're doing something like this:
$('input:checkbox').change(function ()
{
// stuff
});
You can prevent the event from bubbling using event.stopPropagation()
:
$('input:checkbox').change(function (e)
{
e.stopPropagation();
});
You can stop event bubbing and prevent other event handlers on the same element from running using event.stopImmediatePropagation()
.
Thanks @Matt Ball but I found this did what I needed:
$('input[name="subtopics_chosen"]:checked').live('change',function()
Before I had
$('input[name="subtopics_chosen"]').live('change',function()
I'll keep your StopPropagation tip for another day, though, I did not know about it.
精彩评论