What is the difference between event.stopPropagation and event.stopImmediatePropagation? - Just Crack Interview

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

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

Ques:- What is the difference between event.stopPropagation and event.stopImmediatePropagation?
1 1078

One Answer on this Question

  1. 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.
    Hide Copy Code
    $(“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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top