Common Events
Common Events
Section titled “Common Events”Introduction
Section titled “Introduction”Different event types fire for different user interactions. Here are the most commonly used ones.
Mouse Events
Section titled “Mouse Events”element.addEventListener('click', handler); // Single clickelement.addEventListener('dblclick', handler); // Double clickelement.addEventListener('mouseenter', handler); // Hover startelement.addEventListener('mouseleave', handler); // Hover endelement.addEventListener('mousemove', handler); // Mouse moveelement.addEventListener('contextmenu', handler); // Right clickelement.addEventListener('mousedown', handler); // Mouse button pressedelement.addEventListener('mouseup', handler); // Mouse button releasedKeyboard Events
Section titled “Keyboard Events”document.addEventListener('keydown', handler); // Key presseddocument.addEventListener('keyup', handler); // Key released// Note: keypress is deprecated — use keydown insteadFocus Events
Section titled “Focus Events”input.addEventListener('focus', handler); // Element focusedinput.addEventListener('blur', handler); // Lost focusinput.addEventListener('focusin', handler); // Focus bubbles (unlike focus)input.addEventListener('focusout', handler); // Blur bubbles (unlike blur)Form and Window Events
Section titled “Form and Window Events”// Formform.addEventListener('submit', handler); // Form submittedform.addEventListener('reset', handler); // Form reset
// Windowwindow.addEventListener('scroll', handler);window.addEventListener('resize', handler);window.addEventListener('load', handler); // Page fully loadedwindow.addEventListener('DOMContentLoaded', handler); // DOM ready (before images)Summary
Section titled “Summary”- Mouse: click, mouseenter, mouseleave, mousemove
- Keyboard: keydown, keyup
- Focus: focus, blur, focusin, focusout
- Form: submit, reset
- Window: scroll, resize, load, DOMContentLoaded