Events are actions or occurrences that happen in the system you are programming, which the system tells you about so you can respond to them in some wayif required.
Checkout this video:
Your code can respond to events by executing the appropriate code. For example, you could display a message to the user when they click a button, or fetch new data from the server when an HTTP request completes.
What are events?
What are event handlers?
In order to create an event handler, you need two things:
– An HTML element to trigger the event (a button, for example)
What are event listeners?
Event listeners are functions that will be called when a specified event occurs. They are registered with an EventTarget using the EventTarget.addEventListener() method, and removed with the EventTarget.removeEventListener() method. When an event occurs, the registered EventListener is called with the event object as argument.
An EventListener can be registered to listen for multiple events, and an event can register multiple EventListeners.
Types of events
Mouse events are one of the most fundamental ways to interact with elements in the DOM. These events occur when the user presses, releases, or clicks a mouse button on an element. You can use event handlers to respond to these events.
There are three types of mouse events:
-mousedown – occurring when the user presses a mouse button
-mouseup – occurring when the user releases a mouse button
-click – occurring when the user clicks (presses and releases) a mouse button
Keyboard events are those that occur when you press or release a key on a keyboard. They are designated by the keyword “keydown,” “keypress,” or “keyup.”
“Keydown” indicates that a key has been pressed. “Keypress” is triggered when a key is pressed, and then released. “Keyup” occurs when a key is released.
Last updated: May 4, 2019
Form events happen when the user interacts with a form element. The most common form event is probably the “submit” event, which is fired when the user submits a form.
There are many other form events, though, such as “focus”, “blur”, “change”, “select”, etc. Each event has its own purpose and function.
Here’s a list of some of the most common form events:
-Submit: Fired when the user submits a form.
-Focus: Fired when an element (usually a text field) receives focus.
-Blur: Fired when an element loses focus.
-Change: Fired when the value of an element is changed (usually a text field).
-Select: Fired when the user selectes text in a text field.
Document events fire when something happens in the document, such as the document loading, unloading, or changing.
Once an event has been triggered, any code that has been registered as a listener for that event will be executed. This allows you to write code that will respond to events in a flexible and powerful way.