Earid

addEventListener()

16/06/2020

by Earid

The addEventListener() method attaches an event handler to the specified element.

Syntax

target.addEventListener(type, listener [, options]);
target.addEventListener(type, listener [, useCapture]);
target.addEventListener(type, listener [, useCapture, wantsUntrusted  ]);
Parameter Description
event Required. A String that specifies the name of the event.

Note: Do not use the “on” prefix. For example, use “click” instead of “onclick”.

For a list of all HTML DOM events, look at our complete HTML DOM Event Object Reference.
function Required. Specifies the function to run when the event occurs.

When the event occurs, an event object is passed to the function as the first parameter. The type of the event object depends on the specified event. For example, the “click” event belongs to the MouseEvent object.
useCapture Optional. A Boolean value that specifies whether the event should be executed in the capturing or in the bubbling phase.

Possible values:
  • true – The event handler is executed in the capturing phase
  • false- Default. The event handler is executed in the bubbling phase
Facebook
X
LinkedIn
Email
Pinterest
WhatsApp

addEventListener()