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



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

Answer / 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

More jQuery Interview Questions

What is the advantage of using minimized version of jQuery?

0 Answers  


Why we use chaining in jquery?

0 Answers  


What happen if you return false from a jQuery event handler?

0 Answers  


What are the slow selectors in jQuery?

1 Answers  


What is jQuery.noConflict?

1 Answers  






Difference between parent() and parents() in jQuery?

0 Answers  


What are the fastest selectors in jQuery?

1 Answers  


Do we need to add jQuery file in both Master and Content page?

0 Answers  


How can jquery be used in conjunction with another javascript library that also uses $ for naming?

0 Answers  


How can events be prevented to work after an ajax request?

0 Answers  


How to check variable is empty or not in jquery?

0 Answers  


What the use of $ symbol in jquery.

0 Answers  


Categories