Guided Notes

Events

addEventListener, common events, the event object, event delegation, and preventing default behavior.

Listening for events

Slide 1 / 5

el.addEventListener('click', handler);

The handler is a function that runs every time the event happens. You can add several listeners to the same element, and remove one later with removeEventListener (pass the same named function).

Avoid inline handlers like onclick="…" in HTML β€” addEventListener keeps behavior in your JavaScript file and allows multiple listeners.

← DOM Manipulation