0Pricing
JavaScript Academy · Lesson

The Event Object

Read event details like target and type.

The Event Argument

When an event fires, the browser passes an event object to your handler. It carries details about what happened and which elements are involved.

btn.addEventListener("click", (event) => {
  console.log(event.type); // "click"
});

event.type

event.type is the name of the event, letting one handler react differently to different event types.

function handle(e) {
  console.log("Got a " + e.type + " event");
}

All lessons in this course

  1. addEventListener Basics
  2. The Event Object
  3. preventDefault and stopPropagation
  4. Keyboard and Mouse Events
← Back to JavaScript Academy