What is the difference between stopPropagation and stopImmediatePropagation?

2

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?

    
asked by anonymous 26.05.2017 / 20:48

1 answer

2

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" );
});
    
26.05.2017 / 20:58