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?
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?
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 javascript events
You are not signed in. Login or sign up in order to post.