
1. Mouse Events
Event | Description |
---|---|
onClick | Fires when an element is clicked. |
onDoubleClick | Fires when an element is double-clicked. |
onMouseDown | Fires when the mouse button is pressed down. |
onMouseUp | Fires when the mouse button is released. |
onMouseMove | Fires when the mouse moves over an element. |
onMouseEnter | Fires when the mouse enters an element (doesn’t bubble). |
onMouseLeave | Fires when the mouse leaves an element (doesn’t bubble). |
onMouseOver | Fires when the mouse enters an element or its children. |
onMouseOut | Fires when the mouse leaves an element or its children. |
2. Keyboard Events
Event | Description |
---|---|
onKeyDown | Fires when a key is pressed down. |
onKeyPress (Deprecated) | Fires when a key is pressed (use onKeyDown instead). |
onKeyUp | Fires when a key is released. |
3. Form Events
Event | Description |
---|---|
onChange | Fires when the value of an input, textarea, or select changes. |
onInput | Fires when the user inputs text. |
onSubmit | Fires when a form is submitted. |
onReset | Fires when a form is reset. |
onFocus | Fires when an element gains focus. |
onBlur | Fires when an element loses focus. |
4. Clipboard Events
Event | Description |
---|---|
onCopy | Fires when the user copies content. |
onCut | Fires when the user cuts content. |
onPaste | Fires when the user pastes content. |
5. Drag & Drop Events
Event | Description |
---|---|
onDrag | Fires when an element is being dragged. |
onDragStart | Fires when the drag starts. |
onDragEnd | Fires when the drag ends. |
onDragOver | Fires when an element is dragged over a valid drop target. |
onDragEnter | Fires when the dragged element enters a valid drop target. |
onDragLeave | Fires when the dragged element leaves a valid drop target. |
onDrop | Fires when a dragged element is dropped. |
6. Touch Events (Mobile)
Event | Description |
---|---|
onTouchStart | Fires when a touch point is placed on the screen. |
onTouchMove | Fires when a touch point moves on the screen. |
onTouchEnd | Fires when a touch point is removed from the screen. |
onTouchCancel | Fires when a touch event is canceled. |
7. Focus Events
Event | Description |
---|---|
onFocus | Fires when an element gains focus. |
onBlur | Fires when an element loses focus. |
8. Window & Document Events
Event | Description |
---|---|
onLoad | Fires when a page has loaded. |
onUnload | Fires when a page is unloaded or refreshed. |
onResize | Fires when the window is resized. |
onScroll | Fires when the user scrolls the page. |
onBeforeUnload | Fires before the user leaves the page (for warnings). |
9. Media Events
Event | Description |
---|---|
onPlay | Fires when media starts playing. |
onPause | Fires when media is paused. |
onEnded | Fires when media reaches the end. |
onTimeUpdate | Fires when media time updates. |
onVolumeChange | Fires when volume changes. |
10. Animation & Transition Events
Event | Description |
---|---|
onAnimationStart | Fires when a CSS animation starts. |
onAnimationEnd | Fires when a CSS animation ends. |
onAnimationIteration | Fires when a CSS animation repeats. |
onTransitionEnd | Fires when a CSS transition ends. |
React-Specific Synthetic Events
React wraps native DOM events with Synthetic Events for performance optimizations. These events work the same as native events but provide cross-browser consistency.
SyntheticEvent
is a wrapper around native events.- React events use camelCase (
onClick
instead ofonclick
). - React handles events asynchronously for optimization.
Example: Using Events in React
import { useState } from "react";
function EventExample() {
const [text, setText] = useState("");
const handleClick = () => {
alert("Button clicked!");
};
const handleChange = (event) => {
setText(event.target.value);
};
return (
);
}
export default EventExample;
Common JavaScript & React Events
🔥 JavaScript Events
- onclick - Triggered when an element is clicked.
- onmouseover - Fires when the mouse hovers over an element.
- onmouseout - Fires when the mouse leaves an element.
- onkeydown - Triggered when a key is pressed down.
- onkeyup - Fires when a key is released.
- onchange - Occurs when an input value changes.
- onsubmit - Triggered when a form is submitted.
- onload - Fires when a page or resource has loaded.
- onresize - Occurs when the browser window is resized.
⚛️ React-Specific Events
- onClick - Handles click events in React.
- onMouseEnter - Triggers when the mouse enters an element.
- onMouseLeave - Triggers when the mouse leaves an element.
- onChange - Used for handling input field changes.
- onSubmit - Handles form submissions.
- onKeyDown - Fires when a key is pressed.
- onKeyUp - Fires when a key is released.
- onFocus - Triggered when an element gains focus.
- onBlur - Triggered when an element loses focus.
- onDoubleClick - Fires when an element is double-clicked.
- onContextMenu - Fires when a right-click context menu is opened.
JavaScript but mostly React Event because of Camel Case
Below is a list of common events used in JavaScript and React:
1. Mouse Events
Event | Description |
---|---|
onClick | Fires when an element is clicked. |
onDoubleClick | Fires when an element is double-clicked. |
onMouseDown | Fires when the mouse button is pressed down. |
onMouseUp | Fires when the mouse button is released. |
onMouseMove | Fires when the mouse moves over an element. |
onMouseEnter | Fires when the mouse enters an element (doesn't bubble). |
onMouseLeave | Fires when the mouse leaves an element (doesn't bubble). |
onMouseOver | Fires when the mouse enters an element or its children. |
onMouseOut | Fires when the mouse leaves an element or its children. |
2. Keyboard Events
Event | Description |
---|---|
onKeyDown | Fires when a key is pressed down. |
onKeyPress (Deprecated) | Fires when a key is pressed (use onKeyDown instead). |
onKeyUp | Fires when a key is released. |
3. Form Events
Event | Description |
---|---|
onChange | Fires when the value of an input, textarea, or select changes. |
onInput | Fires when the user inputs text. |
onSubmit | Fires when a form is submitted. |
onReset | Fires when a form is reset. |
onFocus | Fires when an element gains focus. |
onBlur | Fires when an element loses focus. |
4. Clipboard Events
Event | Description |
---|---|
onCopy | Fires when the user copies content. |
onCut | Fires when the user cuts content. |
onPaste | Fires when the user pastes content. |
5. Drag & Drop Events
Event | Description |
---|---|
onDrag | Fires when an element is being dragged. |
onDragStart | Fires when the drag starts. |
onDragEnd | Fires when the drag ends. |
onDragOver | Fires when an element is dragged over a valid drop target. |
onDragEnter | Fires when the dragged element enters a valid drop target. |
onDragLeave | Fires when the dragged element leaves a valid drop target. |
onDrop | Fires when a dragged element is dropped. |
6. Window & Document Events
Event | Description |
---|---|
onLoad | Fires when a page has loaded. |
onUnload | Fires when a page is unloaded or refreshed. |
onResize | Fires when the window is resized. |
onScroll | Fires when the user scrolls the page. |
onBeforeUnload | Fires before the user leaves the page (for warnings). |
7. Animation & Transition Events
Event | Description |
---|---|
onAnimationStart | Fires when a CSS animation starts. |
onAnimationEnd | Fires when a CSS animation ends. |
onAnimationIteration | Fires when a CSS animation repeats. |
onTransitionEnd | Fires when a CSS transition ends. |