Solution Review: Event Delegation
Explore event delegation concepts and learn how to stop event bubbling with methods like event.stopPropagation and event.cancelBubble. This lesson helps you understand efficient event handling strategies by attaching event handlers to parent elements, improving your ability to answer related JavaScript interview questions.
We'll cover the following...
Question 1: Solution review
Explanation
Options B & D are correct. Both event.stopPropogation() and event.cancelBubble can be used to stop event bubbling.
A bubbling event will propagate upwards from the target element. For example, in the case of a click event, it will bubble up until it reaches the document object. However, at any point, a handler may decide that the event has been fully processed and stop bubbling. This can be achieved using event.stopProgogation().
Let’s look at an example.
Here’s code with event bubbling:
Now let’s see how the output changes when we ...