An Event Listener is a JavaScript method that waits for a specific user interaction or browser action (like a click, keypress, mouse hover, etc.) to happen on an HTML element and then triggers a function in response.
| Type | Description | Multiple Handlers? | Recommended? |
|---|---|---|---|
| Inline HTML Event | Uses HTML attribute like onclick |
||
| DOM Property | Uses JS like element.onclick |
(last one overwrites) | |
addEventListener() |
Standard JS method to add multiple event listeners |
element.addEventListener("event", function, useCapture);
"click", "keydown", etc.addEventListener() — it supports multiple listeners and works with dynamic
elements.