top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between event.stopPropagation and event.stopImmediatePropagation?

+5 votes
512 views
What is the difference between event.stopPropagation and event.stopImmediatePropagation?
posted Jul 15, 2015 by Shivaranjini

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

event.stopPropagation() allows other handlers on the same element to be executed, while event.stopImmediatePropagation() prevents every event from running. For example, see below jQuery code block.

$("p").click(function(event){
  event.stopImmediatePropagation();
});
$("p").click(function(event){
  // This function won't be executed
  $(this).css("background-color", "#f00");
}); 

If event.stopPropagation was used in previous example, then the next click event on p element which changes the css will fire, but in case event.stopImmediatePropagation(), the next p click event will not fire.

answer Jul 21, 2015 by Karthick.c
...