← JavaScript learning pathJavaScript · Module 8 of 10
Events
React to clicks, typing and form submits with event listeners.
📖 Key ideas
- addEventListener("click", handler) runs code when something happens.
- Common events: click, input, change, submit, keydown, load.
- The event object e tells you what happened (e.target, e.key).
- e.preventDefault() stops the default action, like a form reload.
- 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