What is the difference between stopPropagation and stopImmediatePropagation?

Asked

Viewed 685 times

2

I realized a while ago that it was possible to use these two functions, but what would be the difference between them?

What’s the difference between event.stopPropagation() and event.stopImmediatePropagation() in Javascript?

1 answer

2

stopPropagation() will prevent the handlers of parent elements to shoot.

Already the stopImmediatePropagation(), prevents the handlers of parent elements, and also prevents any other Handler of the same element to shoot. Quick example of 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" );
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.