Search code examples
javascriptjqueryjquery-eventsevent-bubbling

How to stop events bubbling in jQuery?


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;
})

Solution

  • According to jQuery's documentation:

    $('myclass').bind('amodaldestroy'), function(event) {
        ....does something....
        event.stopPropagation();
    });