Skip to main content

Bug Tracker

Side navigation

#6913 closed bug (fixed)

Opened August 17, 2010 04:09PM UTC

Closed April 07, 2011 02:20PM UTC

Last modified April 11, 2012 08:23PM UTC

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

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'

Attachments (0)
Change History (10)

Changed October 15, 2010 04:31AM UTC by snover comment:1

description: \ 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'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'
owner: → metalculus84
priority: → undecided
status: newpending

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

Changed October 18, 2010 04:04PM UTC by metalculus84 comment:2

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/

Changed October 18, 2010 07:00PM UTC by snover comment:3

keywords: namespace, bubbleingnamespace bubbling needsreview
milestone: 1.4.3
priority: undecidedhigh
status: newopen
version: 1.4.21.4.3

Changed November 02, 2010 03:20AM UTC by dmethvin comment:4

Changed December 29, 2010 05:08AM UTC by dmethvin comment:5

owner: metalculus84dmethvin
status: openassigned

Changed February 25, 2011 12:02AM UTC by Torsten85 comment:6

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

Changed March 30, 2011 07:52PM UTC by john comment:7

milestone: → 1.6

Changed April 07, 2011 02:20PM UTC by dmethvin comment:8

resolution: → fixed
status: assignedclosed

Fixed with the 1.6 event reorg.

Changed April 11, 2012 07:59PM UTC by mdleichty@gmail.com comment:9

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.

Changed April 11, 2012 08:23PM UTC by dmethvin comment:10

@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.