Stop jQuery from calling the following events

I am writing a jQuery plugin for the first time, and I am wondering if there is a way to stop jQuery from triggering the following connected events.

Example:

$(this).submit(function(){
    return $(this).do_some_validation();
}

If the validation fails (i.e. the returned function false), the form should not be submitted, but if there are any other event handlers, only the return value of the last handler may prevent the form from being submitted.

+3
source share
5 answers

Use the stopPropagation () method:

$(this).submit(function(e){
    e.stopPropagation();
    return $(this).do_some_validation();
}
+6
source

event.stopImmediatePropagation, stopPropagation " " ( , stopPropagation).

+5

stopPropagation() , , .live() .delegate().

return false; - , stopPropogation .

+1

.live()

jQuery("a.entryTable, a.entryDelete").live("click", function(e) {   
    e.preventDefault();
    e.stopPropagation();

    // code

    return false;
});
0

Source: https://habr.com/ru/post/1752316/


All Articles