Event
Learn how event handlers trigger JavaScript actions on user interactions.
HTML events are "things" that happen to HTML elements. When JavaScript is used in HTML pages, JavaScript can "react" on these events. An HTML event can be something the browser does, or something a user does.
Here are some examples of HTML events:
- When a user clicks the mouse
- When a webpage has loaded
- When an image has been loaded
- When the mouse moves over an element
- When an input field is changed
- When an HTML form is submitted
- When a user strokes a key
JavaScript lets users execute code when events are detected.
Common HTML Event
Event | Description |
---|---|
onchange | It triggers when we change value of any input element. We often use this with an input field a select menu or text area to takes some action when the user changes content value. |
onclick | Get activated when the element in clicked. This is often used to act, like submitting a form or opening up a dialog. |
onmouseover | It activates when the mouse pointer is moved onto an element. It is used to change the style of any element, like highlighting a button on mouse over. |
onmouseout | Triggers when the mouse pointer is moved away from an element. This is for changing styles back or hiding elements that were displayed on a onmouseover. |
onkeydown | Fires when a key is pressed down. This is a mechanism for keyboard shortcuts or validating input as the user types. |
onload | Triggers once the element (usually an image or whole page) has completed loading. This commonly used for initializing scripts or the execution of actions that should only run after the entire content has been loaded (like a redirect). |
onchange
onclick
onmouseover
and onmouseout
onkeydown
onload
Edit on GitHub
Last updated on