aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes stopping event propagation best practice (jQuery) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "stopping event propagation best practice (jQuery)" Watch "stopping event propagation best practice (jQuery)" New topic
Author

stopping event propagation best practice (jQuery)

Rob Dennett
Ranch Hand

Joined: Dec 07, 2010
Posts: 81
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

Joined: Jan 10, 2002
Posts: 61421
    
  67

Return false or call event.stopPropagation().


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rob Dennett
Ranch Hand

Joined: Dec 07, 2010
Posts: 81
Bear Bibeault wrote:Return false or call event.stopPropagation().


Unfortunately, that doesn't work.

Thanks,
Rob
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: stopping event propagation best practice (jQuery)