Events are actions that happen on a web page, such as clicking a button, typing in a box, or moving the mouse.
JavaScript can listen for these events and respond to them. This is what makes websites interactive — buttons work, forms submit, and messages appear when users do something.
Learning how to handle events is essential for building real-world web applications.
Common Events in JavaScript
- click – when a user clicks an element
- mouseover – when the mouse moves over an element
- keydown – when a key is pressed
- change – when input value changes
- submit – when a form is submitted
Events connect user actions with JavaScript logic.
This button will be used to demonstrate how JavaScript responds to user actions.
The addEventListener method listens for an event and runs the given function when the event happens.
Here, the message is shown when the button is clicked.
This example shows how events can change the behavior and content of a page.
By mastering event handling, students gain the ability to build interactive features like buttons, menus, forms, and popups in real-world applications.