Bug Tracker

Modify

Ticket #6913 (closed bug: fixed)

Opened 4 years ago

Last modified 2 years ago

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

Description (last modified by snover) (diff)

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

comment:1 Changed 4 years ago by snover

  • Owner set to metalculus84
  • Priority set to undecided
  • Status changed from new to pending
  • Description modified (diff)

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

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

  • Status changed from pending to new

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 4 years ago by snover

  • Keywords namespace bubbling needsreview added; namespace, bubbleing removed
  • Priority changed from undecided to high
  • Version changed from 1.4.2 to 1.4.3
  • Status changed from new to open
  • Milestone 1.4.3 deleted

comment:4 Changed 3 years ago by dmethvin

comment:5 Changed 3 years ago by dmethvin

  • Owner changed from metalculus84 to dmethvin
  • Status changed from open to assigned

comment:6 Changed 3 years ago by Torsten85

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

comment:7 Changed 3 years ago by john

  • Milestone set to 1.6

comment:8 Changed 3 years ago by dmethvin

  • Status changed from assigned to closed
  • Resolution set to fixed

Fixed with the 1.6 event reorg.

comment:9 Changed 2 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 2 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.

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.