Expanding on the already great snippet from the accepted answer, this is the output using the eventPhase property.
Event bubbling and capturing are two ways of event propagation in the HTML DOM API, when an event occurs in an element inside another element, and both elements have registered a handle for that event. The standard DOM Events describes 3 phases of event propagation: Capturing phase – the event goes down to the element. quirksmode.org has a nice description of this. Now here the question is in which order the event will execute. What is the !! Back in the old days, Netscape advocated event capturing, while Microsoft promoted event bubbling.
Target phase – the event reached the target element. The bubbles event property returns a Boolean value that indicates whether or not an event is a bubbling event. the blanket term for both event bubbling and event capturing If there are two elements element 1 and element 2.
Event Bubbling and Event Capturing is the most used terminology in JavaScript at the time of event flow. What is the difference between event bubbling and capturing? In capturing model, the event will be handled by the div first (click event handlers in the div will fire first), then in the ul, then at the last in the target element, li. In the structure above, assume that a click event occurred in the li element. the event handler of element2 fires first, the event handler of element1 fires last.
var functionName=function(){} vs function functionName(){}. The event propagation mode determines in which order the elements receive the event. Element 2 is inside element 1 and we attach an event handler with both the elements lets say onClick. Note that the browser compatibility is not determined yet. What is the most efficient way to deep clone an object in JavaScript? To use the capturing model pass the third argument as true. Here’s the picture of a click on
What is the difference between Bower and npm.
If the event attached with element 1 executes first it is called event capturing and if the event attached with element 2 executes first this is called event bubbling. "); With bubbling, the event is first captured and handled by the innermost element and then propagated to outer elements. which order the elements receive the event.