I realized a while ago that it was possible to use these two functions, but what would be the difference between them?
What is the difference between event.stopPropagation()
and event.stopImmediatePropagation()
in Javascript?
I realized a while ago that it was possible to use these two functions, but what would be the difference between them?
What is the difference between event.stopPropagation()
and event.stopImmediatePropagation()
in Javascript?
stopPropagation()
will prevent% of parent elements from firing.
While handlers
, prevents% of parent elements , and also prevents any other handlers from the same element from firing.
Quick example documentation :
$( "p" ).click(function( event ) {
event.stopImmediatePropagation();
});
$( "p" ).click(function( event ) {
// Esse aqui não vai executar, por causa do stopImmediatePropagation no handler anterior
$( this ).css( "background-color", "#f00" );
});