target
The original element that started the event.
The event object contains details about what happened: target, currentTarget, key, pointer position, default behavior and more.
button.addEventListener("click", event => {
console.log(event.target);
console.log(event.currentTarget);
});
Events & Forms
Most event handlers receive an event object as their first argument. It tells you what fired the event and provides event-specific data.
target is where the event started. currentTarget is the element whose listener is currently running. They are often different when events bubble.
Methods such as preventDefault and stopPropagation change how the browser continues after the event.
The original element that started the event.
The element handling the current listener.
Stops the browser default action when appropriate.
key, pointer coordinates, input type and more.
Examples
button.addEventListener("click", event => {
event.currentTarget.disabled = true;
});
button.addEventListener("click", event => {
event.target.disabled = true;
});
// target could be a nested span or icon.
Code patterns
These examples are the event patterns you will reuse constantly: listen, inspect, prevent, delegate, validate and submit.
Useful for delegated events.
list.addEventListener("click", event => {
console.log(event.target);
});
The element the listener was attached to.
button.addEventListener("click", event => {
event.currentTarget.disabled = true;
});
Only when handling submission yourself.
form.addEventListener("submit", event => {
event.preventDefault();
});
Keyboard events expose key.
window.addEventListener("keydown", event => {
if (event.key === "Escape") closePanel();
});
Rules that matter
Events are user-facing code. Good handlers stay small, respect native behavior and keep visual, semantic and data state aligned.
They answer different questions.
Do not block useful browser behavior without replacing it.
It can make other features impossible to observe.
Keyboard, pointer and form events expose different details.
Use the event argument instead of window.event.
Extract what you need and pass it to smaller functions.
Production thinking
Understanding the event object prevents the classic bug where a handler changes the wrong element.
Keyboard and form events carry data that helps you support non-mouse interaction correctly.
Production handlers should use the event object deliberately and avoid blocking default behavior without a reason.
Form and link behavior should remain predictable when scripts fail or events are not attached.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
If you can explain what fires, where it fires and what default behavior remains, you understand the interaction.