Bug Tracker

Modify

Ticket #5378 (closed bug: invalid)

Opened 4 years ago

Last modified 4 years ago

click event of a parent triggered when clicking children

Reported by: the_hero Owned by: brandon
Priority: major Milestone: 1.4
Component: event Version: 1.3.2
Keywords: Cc:
Blocking: Blocked by:

Description

Parent element click events are triggered on children elements,

When you assign a click event to a parent element there is currently no way to stop this event from triggering when clicking a child of this parent.

In some situations this is necessary. It is nice to be able to just assign the event to the parent and not worry that it won't be triggered when clicking anywhere inside it including the children. However, much of the time people will have a parent element that does something other than than the parent, sometimes opposite.

Try the attached code to test.

Attachments

test_events.html Download (1.1 KB) - added by the_hero 4 years ago.
Test this code to see this occurring

Change History

Changed 4 years ago by the_hero

Test this code to see this occurring

comment:1 Changed 4 years ago by the_hero

Unbind on the children does not block the parent event from being triggered.

comment:2 Changed 4 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

Click events bubble all the way up to the document, since the parent elements contain the child that was clicked. If you don't want the parent element(s) to act on the click, have their event handler check for event.target==this and return if it is not.

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.