Bug Tracker

Opened 14 years ago

Closed 14 years ago

#5378 closed bug (invalid)

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:
Blocked by: Blocking:

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 (1)

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

Download all attachments as: .zip

Change History (3)

Changed 14 years ago by the_hero

Attachment: test_events.html added

Test this code to see this occurring

comment:1 Changed 14 years ago by the_hero

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

comment:2 Changed 14 years ago by dmethvin

Resolution: invalid
Status: newclosed

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.

Note: See TracTickets for help on using tickets.