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

How to increase cursor size in html body using jquery?

0 Answers  


What is the advantage of using the minified version of jquery rather than using the conventional one?

0 Answers  


How do you implement animation functionality?

1 Answers  


What is queue() in jquery?

0 Answers  


What are the slow selectors in jQuery?

1 Answers  






Do we need to add the jquery file both at the master page and content page as well?

0 Answers  


Define cache paremeter of jquery ajax method?

0 Answers  


How can images be made to appear scrolling one over another?

0 Answers  


Why is jquery better than javascript?

0 Answers  


Consider a scenario where things can be done easily with javascript, would you still prefer jQuery?

1 Answers  


Can we use protocol less URL while referencing jQuery from CDNs?

1 Answers  


What is the difference between .js and .min.js?

1 Answers  


Categories