An Event object describes something that happened: a click, a key press, a form submit, and more. Listeners receive that object as their argument.
Useful fields include type and target. Methods such as preventDefault() cancel the browser’s default action, and stopPropagation() stops the event from moving further through the tree.
This page teaches what Event is. Constructor, methods, and properties live under the Event section.
Listeners get the Event object.
button.addEventListener("click", (event) => { ... }) — use event to read target and call preventDefault().
Syntax
JavaScript Syntax
Common Event patterns:
JavaScript
button.addEventListener("click", function (event) {
console.log(event.type); // "click"
console.log(event.target); // the clicked node
event.preventDefault();
});
Reference
Core Ideas
Ideas every JavaScript Event tutorial builds on:
Idea
Example
Remember
type
event.type
Name like "click"
target
event.target
Origin node
currentTarget
event.currentTarget
Node with this listener
preventDefault
event.preventDefault()
Cancel default action
stopPropagation
event.stopPropagation()
Stop bubbling/capturing
bubbles
event.bubbles
Whether it bubbles up
Code
JavaScript Examples
Three short programs that show how Event works in a JS tutorial.
Example 1 — Read the event type
The type string matches the name you listened for.
JavaScript
const event = new Event("save");
console.log(event.type);
console.log(event.bubbles);
Output
save
false
How It Works
new Event("save") builds an event named save.
type is "save".
bubbles defaults to false unless you pass options.
Example 2 — Cancel a default action
Call preventDefault inside the listener when you handle the action yourself.
JavaScript
link.addEventListener("click", function (event) {
event.preventDefault();
console.log("stayed on page");
});
Output
stayed on page
How It Works
click on a link would navigate by default.
preventDefault() cancels that navigation.
Your code can still run after the call.
Example 3 — Use event.target
target is the node that originated the event.
JavaScript
list.addEventListener("click", function (event) {
console.log(event.target.tagName);
});
Output
BUTTON
How It Works
The listener is on a parent list.
Clicking a button inside sets target to that button.
tagName shows which kind of node was clicked.
Continue
Next: Event Guides
After you know what Event is, open the constructor and method pages.
An Event is an object that describes something that happened in the page, such as a click. Listeners receive it and can read type, target, and call preventDefault.
target is where the event started. currentTarget is the element whose listener is running now, which may be a parent during bubbling.
When the browser would do something you want to replace, such as following a link or submitting a form, and your code handles it instead.
It stops the event from reaching other listeners on ancestors. Use it sparingly; often preventDefault is enough.
Open the Event constructor, then EventTarget for addEventListener, and MouseEvent for click details.