• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

stopping event propagation best practice (jQuery)

 
Rob Dennett
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some code similar to this:



The problem is that the custom event 'myCustomEvent' is getting triggered once for the element that is actually bound to it and once for each of its children. I am trying to implement a publish/subscribe model here where I trigger the custom event and whoever wants to can respond to it. What is the best practice for getting the event to trigger only for the element that was actually bound to it?

Thanks,
Rob
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64721
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Return false or call event.stopPropagation().
 
Rob Dennett
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Return false or call event.stopPropagation().


Unfortunately, that doesn't work.

Thanks,
Rob
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic