What are events and event listeners in JavaScript?

An event is something that happens on the page, like a click, a key press or a form submit. An event listener is a function that runs when the event happens.

button.addEventListener("click", (event) => {
  console.log("Clicked: " + event.target.id);
});

You can add many listeners to one event. See DOM EventListener.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.