Events in JavaScript

Events in JavaScript are browser reactions to user actions or changes on the page. When a user clicks on a button, enters text, moves the mouse, or loads a page, the browser generates an appropriate event that can be handled using JavaScript.

An event is a browser’s signal that some action has taken place. For example:

  • The user clicked on the button (click).

  • The mouse cursor hovered over the element (mouseover).

  • The form has been submitted (submit).

  • The key on the keyboard is pressed (`keydown’).

  • The page has loaded (load).

JavaScript allows you to track these events and perform the necessary actions using event handlers.

The most common events in JavaScript

EventDescription
clickClick on an element
dblclickDouble click
mousedownClicking the mouse button
mouseupReleasing the mouse button
mousemoveMouse movement
mouseoverHovering over an element
mouseoutMoving the cursor away from the element
keydownPressing a key
keyupReleasing the key
inputEntering data in the field
changeChanging the value
submitSubmitting the form
focusFocus on the element
blurLoss of focus
loadPage loading
scrollScrolling
resizeChanging the window size

Event handlers are different, but here’s an example with one of them

<button onclick="alert('The button is pressed!')">Push me</button>
``

Home About Links

Text me