How do I stop custom event bubbling in jQuery?
For example I have this code:
$('.myclass').bind('amodaldestroy', function(){ ....does something..... })
How do I only allow this to be triggered once on the first element it finds when bubbling? Can I just add return false
?
$('.myclass').bind('amodaldestroy', function(){ ....does something..... return false; })
The event. stopPropagation() method stops the bubbling of an event to parent elements, preventing any parent event handlers from being executed. Tip: Use the event. isPropagationStopped() method to check whether this method was called for the event.
The concept of "bubbling up" is like if you have a child element with a click event and you don't want it to trigger the click event of the parent. You could use event. stopPropagation() . event.
stopPropagation()Returns: undefined. Description: Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.
According to jQuery's documentation:
$('myclass').bind('amodaldestroy'), function(event) { ....does something.... event.stopPropagation(); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With