DOM Events
An event listener registers code to run when an event is dispatched. event.target identifies the originating target; currentTarget identifies the listener’s current element.
Register the response now; execute it when the interaction happens.
See the mechanism
click listener"Not saved"Follow one example
The listener is attached to the button. Clicking its inner span may make target the span, while currentTarget remains the button during this handler. The status changes only when the event fires. Native buttons support keyboard activation; a click listener on a decorative div does not automatically provide equivalent semantics. A production save operation also needs persistence and failure handling.
Predict, change and check
Predict: If the inner span receives the click, which property should you use to disable the button holding the listener?
Test your explanation: Click the text, then activate the button with the keyboard after resetting the preview. Extend the mini-project: show a saved count and add a second article without using inline onclick attributes.
The tasks below ask you to explain that result and apply the idea to different inputs.
Apply and distinguish
Follow the event through its route
Events can move through capture and bubbling phases. A listener on a parent can handle events from matching descendants, which is useful for a changing list. event.target identifies the origin, while currentTarget identifies the element whose listener is currently running. Not every event bubbles in the same way.
preventDefault cancels an event's cancelable default action, such as submitting a form, but does not mean 'stop bubbling'. stopPropagation affects propagation and does not automatically cancel a default action. Remove listeners with the matching callback and capture setting, or own them with a supported AbortSignal. Native controls still need accessible labels and visible focus.
Check your understanding: State the input contract, identify the operation that changes the result, and give one boundary input that would distinguish the correct rule from the mistake described above.