Skip to main content

Bug Tracker

Side navigation

#10673 closed bug (worksforme)

Opened November 04, 2011 03:50PM UTC

Closed November 04, 2011 04:32PM UTC

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:

http://jsfiddle.net/HKGsT/

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.

Attachments (0)
Change History (2)

Changed November 04, 2011 03:51PM UTC by dcherman comment:1

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

http://jsfiddle.net/HKGsT/1/

Changed November 04, 2011 04:32PM UTC by dmethvin comment:2

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.

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.