Bug Tracker

Opened 13 years ago

Closed 12 years ago

Last modified 11 years ago

#6913 closed bug (fixed)

namespaced event bubbleing wrong

Reported by: metalculus84 Owned by: dmethvin
Priority: high Milestone: 1.6
Component: event Version: 1.4.3
Keywords: namespace bubbling needsreview Cc:
Blocked by: Blocking:

Description (last modified by snover)

Html code

<div class="parent">

<div class="child1" > </div> <div class="child2"> </div>

</div>

<a class="btn1">customClick.btn1</a> <a class="btn2">customClick.btn2</a>

jQuery code

jQuery('div.child1')

.bind('customClick.btn1', function () {

alert('child1 reacted to customClick.btn1');

});

jQuery('div.child2')

.bind('customClick.btn2', function () {

alert('child2 reacted to customClick.btn2');

});

jQuery('div.parent')

.bind('customClick.btn1', function (e) {

alert('parent reacted to customClick.btn1');

}) .bind('customClick.btn2', function (e) {

alert('parent reacted to customClick.btn2');

});

jQuery('a.btn1')

.click(function(){

jQuery('div.child1').trigger('customClick.btn1');

});

jQuery('a.btn2')

.click(function(){

jQuery('div.child2').trigger('customClick.btn2');

});

When clicking a.btn1, as expected, the customClick.btn1 event is handled by div.child1 and not div.child2. What is not expected is that the 'customClick' event bubbles and triggers the handlers on div.parent for both 'customClick.btn1' and 'customClick.btn2'. Is this right? Is there anyway to have custom events only bubble the event with the namespace that was triggered. In other words, when 'customClick.btn1' is triggered, not all parent handlers for 'customClick' are handled, just ones that handle 'customClick.btn1'

Change History (10)

comment:1 Changed 13 years ago by snover

Description: modified (diff)
Owner: set to metalculus84
Priority: undecided
Status: newpending

Could you please provide a live test case at jsFiddle? Thanks.

comment:2 in reply to:  description Changed 13 years ago by metalculus84

Status: pendingnew

When clicking a.btn1, as expected, the customClick.btn1 event is handled by div.child1 and not div.child2. What is not expected is that the 'customClick' event bubbles and triggers the handlers on div.parent for both 'customClick.btn1' and 'customClick.btn2'. Is this right? Is there anyway to have custom events only bubble the event with the namespace that was triggered. In other words, when 'customClick.btn1' is triggered, not all parent handlers for 'customClick' are handled, just ones that handle 'customClick.btn1'

http://jsfiddle.net/metalculus84/9ySrc/1/

comment:3 Changed 13 years ago by snover

Keywords: bubbling needsreview added; bubbleing removed
Milestone: 1.4.3
Priority: undecidedhigh
Status: newopen
Version: 1.4.21.4.3

comment:5 Changed 12 years ago by dmethvin

Owner: changed from metalculus84 to dmethvin
Status: openassigned

comment:6 Changed 12 years ago by Torsten85

I encountered the same bug. Simple test can be found here: http://jsfiddle.net/RajTa/

comment:7 Changed 12 years ago by john

Milestone: 1.6

comment:8 Changed 12 years ago by dmethvin

Resolution: fixed
Status: assignedclosed

Fixed with the 1.6 event reorg.

comment:9 Changed 11 years ago by mdleichty@…

This is still not fixed, as of jQuery 1.7.2.

For example:

$('#myelement').on('update.game', myFunc); $.event.trigger('update.global');

myFunc() will fire.

comment:10 Changed 11 years ago by dmethvin

@mdleichty, works fine with the DOCUMENTED interfaces and proper arguments: http://jsfiddle.net/dmethvin/rAkeb/

jQuery.event.trigger is not a publicly documented interface, and may change without warning or deprecation.

Note: See TracTickets for help on using tickets.