Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript

How to addEventListener() in Javascript

Sarvech Qadir

The addEventListener() method attaches an event handler to the specified element – it is supported in many browsers such as Google Chrome, Mozilla Firefox, Safari, Opera, and the latest versions of Internet Explorer.

Syntax

element.addEventListener(event, function, useCapture)

event: Required parameter. Name of the event that is to be clicked. Data type is string.

function: Required parameter. The function is supposed to be executed when the event is clicked.

function can be both internal and external functions.

useCapture: Optional parameter. A boolean value indicates whether the event handler is supposed to be executed in the bubbling or the capturing phase.

if true:
  capturing phase
else:
  bubbling phase

Code

onclick()

mouseover

mouseout

RELATED TAGS

javascript

CONTRIBUTOR

Sarvech Qadir
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring