JavaScript · Middle · Question 42 of 75
How does stopPropagation differ from stopImmediatePropagation?
- ✓Correct answer: The second also prevents other handlers on the same element from running
- 2The first stops both bubbling and the browser's default action
- 3They're synonyms; the second is kept for old browser compatibility
Explanation
stopPropagation stops propagation to other elements, but the remaining handlers on the current element still run. stopImmediatePropagation stops them too. Only preventDefault cancels the default action. Don't overuse stopping propagation - it breaks delegation.