Bug Tracker

Modify

Ticket #10673 (closed bug: worksforme)

Opened 20 months ago

Last modified 20 months ago

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:

 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.

Change History

comment:1 Changed 20 months ago by dcherman

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

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

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.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.