Lesson 3.1Lesson 12 of 24
Events and propagation
Given a business requirement, utilize Events, event handlers, and propagation.
Key points
- 1A click travels in three phases: capture from window down to the target, the target itself, then bubbling back up to window.
- 2Listeners run in the bubbling phase by default. Pass true or { capture: true } as the third argument to run in the capture phase.
- 3stopPropagation stops the event from travelling further along its path, so elements after this one never get it. preventDefault cancels the browser's default action, such as following a link or submitting a form.
- 4removeEventListener needs the same function reference and capture flag. An AbortController signal removes many listeners with one abort call.
- 5new CustomEvent(type, { detail, bubbles }) carries data; dispatchEvent runs the listeners synchronously and returns false if a listener cancelled a cancelable event.
What the exam guide checks here
Objective wording from the exam guide (English).
- 3.1.K1addEventListener options, removeEventListener, the event object
- 3.1.K2Capturing and bubbling, stopPropagation, preventDefault, event delegation
- 3.1.K3Custom events: CustomEvent and dispatchEvent
- 3.1.S1Choose the handler setup that reacts to the right events in the right order
Lock it in
Answer scenario questions on this topic. Every option comes with an explanation.
Practise 3.1 · 12 questions