Event Handling in JavaScript
Event Introduction
-
Events are at the very core of any web application and most JavaScript enhancements.
-
It’s through these events that we define when something is going to happen.
-
If we have a button in our document and we need some form validation to take place when it’s clicked then we would use the ‘click’ event.
What Is An Event ?
The building blocks of an interactive web page is the JavaScript event system.
An event in JavaScript is something that happens with or on the webpage.
A few example of events:
-
A mouse click.
-
The webpage loading.
-
Mousing over a hot spot on the webpage, also known as hovering.
-
Selecting an input box in an HTML form.
-
A keystroke
What Is Event Handling ?
Whenever an event occurs , JavaScript allows us to execute a piece of code in it’s response.
Such kind of programming is called “EVENT HANDLING” and such codes are called “EVENT HANDLERS”.
For example:
User types something in a textbox for mobile number.
This is an EVENT.
A JavaScript code immediately runs and checks whether the typed data is digit or not.
This is EVENT HANDLING.
Event Categories
Before we can design event handling code we must know about types of events .
Overall there are 50 events , but we generally deal with 4 categories of events:
-
Mouse Event
-
Key Event
-
Form Events
-
General Events