Events
Published Jul 30, 2021Updated Feb 19, 2025
Contribute to Docs
Events in JavaScript represent actions or occurrences detected by the browser, often triggered by user interactions or system processes. These events enable web pages to respond dynamically, allowing changes to content, styles, or behaviors when specific actions occur.
Events occur when actions are performed on HTML elements, such as clicking a button, entering text in an input field, or submitting a form. JavaScript provides the ability to detect and respond to these events, making it possible to create dynamic and interactive web applications. JavaScript can handle events in two primary ways:
- By embedding JavaScript code directly within an HTML event attribute (inline event handling).
- By defining an event handler in a separate script, which executes when the event occurs (using DOM properties or the
addEventListener
method).
Types of Events
Event Type | Description | Common Events |
---|---|---|
Mouse Events | Triggered by mouse interactions. | click , dblclick , mousedown , mouseup , mousemove , mouseenter , mouseleave |
Keyboard Events | Triggered by keyboard actions. | keydown , keyup , keypress |
Form Events | Triggered when interacting with form elements. | submit , change , input , focus , blur |
Window Events | Triggered by browser window actions. | load , resize , scroll , unload |
Touch Events | Triggered by touch gestures (mobile devices). | touchstart , touchmove , touchend |
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn JavaScript on Codecademy
- Skill path
Create a Back-End App with JavaScript
Learn how to build back-end web APIs using Express.js, Node.js, SQL, and a Node.js-SQLite database library.Includes 8 CoursesWith CertificateBeginner Friendly30 hours - Free course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner Friendly15 hours