Event Listeners
addEventListener(event, handler) — the modern way to handle events.
Common Events
| Type | Events |
|---|---|
| Mouse | click, mouseenter, mouseleave |
| Keyboard | keydown, keyup |
| Form | submit, change, input |
| Window | load, resize, scroll |
addEventListener(event, handler) — the modern way to handle events.
| Type | Events |
|---|---|
| Mouse | click, mouseenter, mouseleave |
| Keyboard | keydown, keyup |
| Form | submit, change, input |
| Window | load, resize, scroll |
document.querySelector('#btn').addEventListener('click', e=>{
console.log('Clicked!', e.target);
});
form.addEventListener('submit', e=>{
e.preventDefault(); // stop page reload
processForm();
});
More in JavaScript