Events refer to the actions that are detected by a programming language when you perform a particular task.
Example: the onclick event detected by the programming language when you click the mouse button.
Events are generally used in combination with the function, implying that when an event occurs, it calls a specified function. An event commonly occurs when a user clicks the mouse button , web page is loaded, or from field is changed. Events are handled by a special function, known as event handler, which handles a particular event when the event is triggered.
How to Create an Event handler :
In the above code OnEvent refers to the name of an event followed by an equal sign and the code that executes when the event is triggered.
Let’s do some Exercise :
Working with onclick Event :
The onclick event triggers when you click a particular control, such as button control. Let’s create a webpage to understand the onclick event :
Here we defined the onclick event that occurs when we click on ‘Click me ‘ button.
Here this alert box appears because of onclick event and this event occurs when we hit on ‘Click me’ button.
Some Keyboard Events which are used in HTML:
*New in HTML5