Events in JavaScript

Creating ElementsEvent Listeners

Events are things that happen in the browser: a user clicks a button, moves the mouse, presses a key, submits a form, or the page finishes loading. JavaScript can 'listen' for these events and run code in response.

This is what makes web pages interactive – without events, nothing responds to the user.

Common Event Types

  • Mouse events: click, dblclick, mouseover, mouseout, mousemove
  • Keyboard events: keydown, keyup, keypress
  • Form events: submit, change, input, focus, blur
  • Window/page events: load, resize, scroll
  • Other: touchstart/touchend for mobile

The Event Object

When an event happens, the browser creates an event object with details: which element, mouse position, pressed key, etc.

Basic Event Examples

Keyboard Events

Form Events

Quick Quiz

We have reviewed and checked the materials, but errors may still occur. The content is provided for educational purposes only, so use it at your own responsibility and verify with other sources if needed.

✨ Ask Lara — your AI study partner

Unlock personalized learning support. Lara can explain lessons, summarize topics, and answer your study questions — available from the Go plan and above.


Lara helps you learn faster — exclusive to ReadyTools Go, Plus, and Max members.

Track Your Progress 🚀

Learn more easily by tracking your progress completely for free.