Opened 11 years ago
Closed 11 years ago
#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: | ||
Blocked by: | Blocking: |
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 (2)
comment:1 Changed 11 years ago by
comment:2 Changed 11 years ago by
Resolution: | → worksforme |
---|---|
Status: | new → closed |
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.
Linked a slightly older fiddle - this one demonstrates the event delegation bit:
http://jsfiddle.net/HKGsT/1/