Ticket #10673 (closed bug: worksforme)
Label .on('click') may fire twice
| Reported by: | dcherman | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | None |
| Component: | unfiled | Version: | git |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
See the following test case:
Essentially since clicking the label also causes a native click event to be thrown on the associated input element, a click event may be handled twice if the input element is a child of the label (implicit association). Messes with event delegation a bit also.
Change History
comment:2 Changed 20 months ago by dmethvin
- Status changed from new to closed
- Resolution set to worksforme
It's just normal event bubbling, slightly complicated by the fact that the browser clicks the check box when you click the label. As you noted, the event targets are different, you just get two clicks because the label is the parent of the check box.
http://jsfiddle.net/dmethvin/HKGsT/2/
I don't think we can/should try to mask what is going on by swallowing one of the events. You can fix it several ways, by changing the markup, putting the click event on the checkbox, or delegating to the checkbox for the label click.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Linked a slightly older fiddle - this one demonstrates the event delegation bit:
http://jsfiddle.net/HKGsT/1/