Common Events List for addEventListener
Mouse Eventsβ
| Event | Description |
|---|---|
| click | When the user clicks |
| dblclick | Double click |
| mouseover | When the cursor enters an element |
| mouseout | When the cursor leaves the element |
| mousemove | When the cursor moves over an element |
| mousedown | When a mouse button is pressed |
| mouseup | When a mouse button is released |
| contextmenu | Right mouse click |
Keyboard Eventsβ
| Event | Description |
|---|---|
| keydown | When a key is pressed |
| keyup | When a key is released |
| keypress | (Deprecated, use keydown) |
Form Eventsβ
| Event | Description |
|---|---|
| submit | When a form is submitted |
| change | When the value of an input/select changes |
| input | When typing (while typing) |
| focus | When an input receives focus |
| blur | When an input loses focus |
| reset | When a form is reset |
π Document or Window Eventsβ
| Event | Description |
|---|---|
| load | When the page has finished loading |
| DOMContentLoaded | When the DOM is ready (before images) |
| resize | When the browser window changes size |
| scroll | When scrolling |
| beforeunload | Before the user closes or reloads the page |
| unload | When the page is closed |
Device Events (touch/screen)β
| Event | Description |
|---|---|
| touchstart | When an element is touched |
| touchmove | When the finger moves on the screen |
| touchend | When the finger is lifted |
| orientationchange | Device orientation change |
Basic Exampleβ
const button = document.getElementById('myButton');
button.addEventListener('click', () => {
alert('Button clicked!');
});