Bug Tracker

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:


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 dcherman

Linked a slightly older fiddle - this one demonstrates the event delegation bit:


comment:2 Changed 11 years ago by dmethvin

Resolution: worksforme
Status: newclosed

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.


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.

Note: See TracTickets for help on using tickets.