In programming, an event is an action that occurs as a result of the user or another source, such as a mouse click. An event handler is a routine that deals with the event, allowing a programmer to write code that is executed when the event occurs.
Other common event examples
- A web browser completely loading a web page.
- A file being created or modified on a filesystem.
- A hardware sensor such as a webcam or microphone receiving sensory input.
- The arrival of incoming network traffic.
- The occurrence of an error at the program or system level.
Events on the Web
Another example of an event is a user clicking a button on a web page. This action creates what is known as a “click” event. JavaScript could then be used to program a reaction to the event, for instance, you could use the onclick event handler shown in the following box:
The code reacts to a click event on the button, sending the “Hello” message the viewer. To see this in action, be sure JavaScript is enabled in your browser and click the button below.
Browser, Error, Event listener, Filesystem, Network, Programming terms, Web page