JavaScript Events – Quick Notes
This PDF contains a complete reference for JavaScript events including categories, syntax,
comparison tables, and real-life use cases for quick revision.
Event Syntax Examples
Inline <button onclick="alert('Hello!')">Click</button>
DOM Level document.getElementById("btn").onclick = function(){ alert("Clicked!"); };
addEventListener (Best) document.getElementById("btn").addEventListener("click", () => alert("Clicked!"));
Comparison Table of Events
Category Event When it Fires Example
Mouse click Single mouse click el.addEventListener("click", fn)
Keyboard keydown Key pressed document.addEventListener("keydown", fn)
Form submit Form submitted form.addEventListener("submit", fn)
Window resize Window resized window.addEventListener("resize", fn)
Clipboard copy Copy action document.addEventListener("copy", fn)
Drag & Drop drop Item dropped zone.addEventListener("drop", fn)
Touch touchstart Finger touches screen document.addEventListener("touchstart", fn)
Media play Media starts playing video.addEventListener("play", fn)
Animation animationend Animation ends el.addEventListener("animationend", fn)
Rare online Browser goes online window.addEventListener("online", fn)
Real-Life Use Cases
Category Event Real-Life Use Case
Mouse click Toggle dark mode, submit form
Keyboard keyup Validate input after typing
Form input Live search suggestions
Window scroll Infinite scroll feed
Clipboard paste Paste Excel data into form
Drag & Drop dragover/drop File upload (Google Drive)
Touch touchmove Swipe gestures on mobile
Media timeupdate Update video progress bar
Animation transitionend Run code after sidebar animation
Rare mutation observerDetect new chat messages