element.addEventListener(event, listener, useCapture);
- useCapture: It is an optional parameter used to control event propagation. A boolean value is passed where “true” denotes capturing phase and “false” denotes the bubbling phase.
Example 1: In this example, we will display text on the webpage after clicking on the button.
Example 2: In this example, two events “mouseover” and “mouseout” are added to the same element. If the text is hovered over then “mouseover” event occurs and the RespondMouseOver function is invoked, similarly for “mouseout” event RespondMouseOut function is invoked.