What is the difference between event.stopPropagation and event.stopImmediatePropagation?
Answer Posted / chaitanya
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.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is .siblings() method in jquery?
How to resolve conflicts with other libraries?
What is the starting point of code execution in jquery?
What is the use of css() method in jquery?
Differentiate among .empty() vs .remove() vs .detach() in jquery.
What is a jquery library?
How to run an event handler only once in jQuery?
How to prevent Right Click option using jquery?
What is the use of jQuery.data() method?
Explain data paremeter of jquery ajax method?
Can we include multiple version of jquery? : jquery mobile
How do you add an HTML element in DOM tree?
Is jquery still relevant 2019?
Why jQuery is needed?
Explain source maps in jquery? : jquery mobile