🌐Browser Event
Also known as DOM Event, Event Listener, JavaScript Event
A sign that something happened on a page, like a click. Code can react to it.
Think of it like
Think of it like a doorbell. When someone presses it, the person inside hears it and goes to the door.
Example
Jack's page listens for clicks on the Buy button. Each click runs a function that adds the item to the cart.
Why it matters
Events are how a page talks back. Every click, tap and key press is one.
Definition
Example code
javascript
button.addEventListener("click", () => {
console.log("Clicked!");
});Common mistake
Key takeaways
- 1Something happened. A click, a key, a load.
- 2Listen for it. Attach a handler to a part.
- 3Run a function. The browser calls your code.