← JavaScript learning path
JavaScript · Module 8 of 10

Events

React to clicks, typing and form submits with event listeners.

📖 Key ideas

  1. addEventListener("click", handler) runs code when something happens.
  2. Common events: click, input, change, submit, keydown, load.
  3. The event object e tells you what happened (e.target, e.key).
  4. e.preventDefault() stops the default action, like a form reload.
  5. Event delegation: one listener on a parent handles many children.
💡 Real-life example: An event listener is a doorbell: when someone presses it (the event), your handler answers the door.
addEventListenerAttaches a handler to an event
e.targetThe element that triggered the event
preventDefaultStops the browser default action
submitEvent fired when a form is sent