JavaScript Events

You are Here:

JavaScript Events

In JavaScript, an event is something that-happen in the system. For example, user clicks an element (button, link, etc.) is an event, page load is an event, hovering an element is an event, and so.

In this section, we will list all the events available in JavaScript.

Mouse Events

The following table provides a list of all Mouse Events available in JavaScript.

EventExplanation
onclickTriggers when the user clicks on an element
oncontextmenuTriggers when the user right-clicks on an element to open a context menu
ondblclickTriggers when the user double-clicks on an element
onmousedownTriggers when the user presses a mouse button over an element
onmouseenterTriggers when the pointer is moved onto an element
onmouseleaveTriggers when the pointer is moved out of an element
onmousemoveTriggers when the pointer is moving while it is over an element
onmouseoverTriggers when the pointer is moved onto an element, or onto one of its children
onmouseoutTriggers when a user moves the mouse pointer out of an element, or out of one of its children
onmouseupTriggers when a user releases a mouse button over an element
onwheelTriggers when a user wheel/scroll a mouse

Mouse Events Properties

The following table provides a list of all Mouse Events properties available in JavaScript.

PropertyExplanation
event.altKeyReturns whether the "ALT" key was pressed when the mouse event was fired
event.buttonReturns which mouse button was pressed when the mouse event was fired
event.buttonsReturns which mouse buttons were pressed when the mouse event was fired
event.clientXReturns the X coordinate of the mouse pointer relative to the current window, when the mouse event was fired
event.clientYReturns the Y coordinate of the mouse pointer relative to the current window, when the mouse event was fired
event.ctrlKeyReturns whether the "CTRL" key was pressed when the mouse event was fired
event.detailReturns a number with details about the event
eventelegram.dogtaKeyReturns whether the "META" key was pressed when the mouse event was fired
event.movementXReturns the X coordinate of the mouse pointer relative to the position of the last mousemove event
event.movementYReturns the Y coordinate of the mouse pointer relative to the position of the last mousemove event
event.offsetXReturns the X coordinate of the mouse pointer relative to the position of the padding edge of the target node
event.offsetYReturns the Y coordinate of the mouse pointer relative to the position of the padding edge of the target node
event.pageXReturns the X coordinate of the mouse pointer relative to the whole document
event.pageYReturns Y coordinate of the mouse pointer relative to the whole document
event.regionReturns the id of the hit region affected by the event. If no hit region is affected, null is returned
event.relatedTargetReturns the secondary target for the event, if there is one.
event.screenXReturns the X coordinate of the mouse pointer relative to the screen.
event.screenYReturns the Y coordinate of the mouse pointer relative to the screen.
event.shiftKeyReturns whether the "SHIFT" key was pressed when the mouse event was fired

Keyboard Events

The following table provides a list of all Keyboard Events available in JavaScript.

EventExplanation
onkeydownTriggers when the user is pressing a key
onkeypressTriggers when the user presses a key
onkeyupTriggers when the user releases a key

Keyboard Events Properties

The following table provides a list of all Keyboard Events properties available in JavaScript.

PropertiesExplanation
event.altKeyReturns whether the "ALT" key was pressed when the key event was fired
event.codeReturns a DOMString with the code value of the physical key represented by the event
event.ctrlKeyReturns whether the "CTRL" key was pressed when the key event was fired
event.isComposingReturns whether the event is fired between after compositionstart and before compositionend.
event.keyReturns a DOMString representing the key value of the key represented by the event
event.locationReturns a Number representing the location of the key on the keyboard or other input device
eventelegram.dogtaKeyReturns whether the "META" key was pressed when the key event was fired
event.repeatReturns whether a key is being hold down repeatedly or not
event.shiftKeyReturns whether the "SHIFT" key was pressed when the key event was fired

Object/Frame Events

The following table provides a list of all Object/Frame Events available in JavaScript.

EventExplanation
onabortTriggers when the loading of a media is aborted
onbeforeunloadTriggers before the document is about to be unloaded
onerrorTriggers when an error occurs while loading an external file
onfullscreenchangeTriggers when an element is displayed in fullscreen mode
onfullscreenerrorTriggers when an element can not be displayed in fullscreen mode
onhashchangeTriggers when there has been changes to the anchor part of a URL
onloadTriggers when an object has loaded
onpageshowTriggers when the user navigates away from a webpage
onpagehideTriggers when the user navigates to a webpage
onresizeTriggers when the document view is resized
onscrollTriggers when an element's scrollbar is being scrolled
onunloadTriggers once a page has unloaded

Form Events

The following table provides a list of all Form Events available in JavaScript.

EventExplanation
onblurTriggers when an element loses focus
onchangeTriggers when the content of a form element, the selection, or the checked state have changed (for <input>, <select>, and <textarea>)
onfocusTriggers when an element gets focus
onfocusinTriggers when an element is about to get focus
onfocusoutTriggers when an element is about to lose focus
oninputTriggers when an element gets user input
oninvalidTriggers when an element is invalid
onresetTriggers when a form is reset
onsearchTriggers when the user writes something in a search field (for <input="search">)
onselectTriggers after the user selects some text (for <input> and <textarea>)
onsubmitTriggers when a form is submitted

Drag Events

The following table provides a list of all Drag Events available in JavaScript.

EventExplanation
ondragTriggers when an element is being dragged
ondragendTriggers when the user has finished dragging an element
ondragenterTriggers when the dragged element enters the drop target
ondragleaveTriggers when the dragged element leaves the drop target
ondragoverTriggers when the dragged element is over the drop target
ondragstartTriggers when the user starts to drag an element
ondropTriggers when the dragged element is dropped on the drop target

Clipboard Events

The following table provides a list of all Clipboard Events available in JavaScript.

EventExplanation
oncopyTriggers when the user copies the content of an element
oncutTriggers when the user cuts the content of an element
onpasteTriggers when the user pastes some content in an element

Print Events

The following table provides a list of all Print Events available in JavaScript.

EventExplanation
onafterprintTriggers when a page has started printing, or if the print dialogue box has been closed
onbeforeprintTriggers when a page is about to be printed

Animation Events

The following table provides a list of all Animation Events available in JavaScript.

EventExplanation
onanimationstartTriggers when a CSS animation has started
onanimationendTriggers when a CSS animation has completed
onanimationiterationTriggers when a CSS animation is repeated

Animation Events Properties

The following table provides a list of all Mouse Events properties available in JavaScript.

PropertyExplanation
event.animationNameReturns the name of the animation
event.elapsedTimeReturns the number of seconds an animation has been running

Media Events

The following table provides a list of all Media Events available in JavaScript.

EventExplanation
onabortTriggers when the loading of an audio/video is aborted
oncanplayTriggers when the browser can start playing the audio/video
oncanplaythroughTriggers when the browser can play through the audio/video without stopping for buffering
ondurationchangeTriggers when the duration of the audio/video is changed
onemptiedTriggers when the current playlist is empty
onendedTriggers when the current playlist is ended
onerrorTriggers when an error occurred during the loading of an audio/video
onloadeddataTriggers when the browser has loaded the current frame of the audio/video
onloadedmetadataTriggers when the browser has loaded meta data for the audio/video
onloadstartTriggers when the browser starts looking for the audio/video
onpauseTriggers when the audio/video has been paused
onplayTriggers when the audio/video has been started or is no longer paused
onplayingTriggers when the audio/video is playing after having been paused or stopped for buffering
onprogressTriggers when the browser is downloading the audio/video
onratechangeTriggers when the playing speed of the audio/video is changed
onseekedTriggers when a seek operation completed
onseekingTriggers when a seek operation begins
onstalledTriggers when the user agent is trying to fetch media data, but data is unexpectedly not forthcoming
onsuspendTriggers when the media data loading has been suspended
ontimeupdateTriggers when the time indicated by the currentTime attribute has been updated
onvolumechangeTriggers when the volume has been changed
onwaitingTriggers when the video stops because it needs to buffer the next frame

Transition Events

The following table provides a list of all Transition Events available in JavaScript.

EventExplanation
ontransitionendTriggers when a CSS transition has completed

Transition Events Properties

The following table provides a list of all Transition Events properties available in JavaScript.

PropertyExplanation
event.persistedReturns whether the webpage was cached by the browser

Server Sent Events

The following table provides a list of all Server Sent Events available in JavaScript.

EventExplanation
onmessageTriggers when a message is received through the event source
onopenTriggers when a connection with the event source is opened
onerrorTriggers when an error occurs while loading an external file

Touch Events

The following table provides a list of all Touch Events available in JavaScript.

EventExplanation
ontouchcancelTriggers when the touch is interrupted
ontouchendTriggers when a finger is removed from a touch screen
ontouchmoveTriggers when a finger is dragged across the screen
ontouchstartTriggers when a finger is placed on a touch screen

HashChangeEvent Properties

The following table provides a list of all HashChange Event properties available in JavaScript.

PropertyExplanation
event.newURLReturns the new URL to which the window is navigating
event.oldURLReturns the previous URL from which the window was navigated

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author