An EventListener is used to listen for an event that happens on an HTML element and execute JavaScript code when that event occurs.
Examples of events:
- 🖱️ click — when you click a button.
- ⌨️ keydown — when you press a keyboard key.
- 🖱️ mouseover — when you move your mouse over an element.
- ✍️ input — when you type in an input field.
- 📄 DOMContentLoaded — when the HTML document has been loaded and parsed.
Syntax:
element.addEventListener("event", function() {
});
Top comments (0)