English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM Events

Sending DOM events is to notify the code of the interesting things that have happened.

Events are usually used in conjunction with functions, and the function will not be executed before the event occurs (for example, when the user clicks a button).

Events can represent everything, from basic user interactions to automatic notifications of things happening in the presentation model.

Activity nameDescriptionEvent Type
abortThis event occurs when the resource loading is aborted.UiEvent, Event
afterprintThis event occurs when the related document has started printing or the print preview has been closed.Event
animationendThis event occurs when the CSS animation is completed.AnimationEvent
animationiterationThis event occurs when the CSS animation is repeated.AnimationEvent
animationstartThis event occurs when the CSS animation starts.AnimationEvent
beforeprintThis event occurs when the related document is about to be printed or previewed for printing.Event
beforeunloadThis event occurs when the window, document, and its resources are about to be unloadedUiEvent, Event
blurThis event occurs when an element loses focus (does not bubble)FocusEvent
canplayThis event occurs when the browser can start playing media (when it has enough buffering to start playing)Event
canplaythroughThis event occurs when the browser can play media without stopping bufferingEvent
changeThis event occurs when the content of a form element, selection, or selected state changes (for <input>, <select>, and <textarea>)Event
clickThis event occurs when the user clicks an elementMouseEvent
contextmenuThis event occurs when the user right-clicks an element to open a context menuMouseEvent
copyThis event occurs when the user copies the content of an elementClipboardEvent
cutThis event occurs when the user cuts the content of an elementClipboardEvent
dblclickThis event occurs when the user double-clicks an elementMouseEvent
dragThis event occurs while dragging an elementDragEvent
dragendThis event occurs when the user finishes dragging the elementDragEvent
dragenterThis event occurs when the dragged element enters the drop targetDragEvent
dragleaveThis event occurs when the dragged element leaves the drop targetDragEvent
dragoverThis event occurs when the dragged element is over the drop targetDragEvent
dragstartThis event occurs when the user starts dragging an elementDragEvent
dropThis event occurs when the dragged element is placed on the drop targetDragEvent
durationchangeThis event occurs when the duration of the media changesEvent
endedThis event occurs when the media reaches the end (useful for messages like 'Thank you for listening')Event
errorThis event occurs when a resource fails to loadProgressEvent, UiEvent, Event
focusAn event occurs when an element has gained focus (does not bubble)FocusEvent
focusinThis event occurs when an element is about to gain focusFocusEvent
focusoutThis event occurs when an element is about to lose focusFocusEvent
fullscreenchangeAn event occurs when an element is displayed in full-screen modeEvent
fullscreenerrorThis event occurs when an element cannot be displayed in full-screen modeEvent
hashchangeThis event occurs when the anchor part of the URL changesHashChangeEvent
inputAn event occurs when an element receives user inputInputEvent, Event
invalidThis event occurs when an element is invalidEvent
keydownThis event occurs when the user presses a keyKeyboardEvent
keypressAn event occurs when the user presses a keyKeyboardEvent
keyupThis event occurs when the user releases a key.KeyboardEvent
loadThis event occurs when the object is loaded.UiEvent, Event
loadeddataThis event occurs when media data is loaded.Event
loadedmetadataThis event occurs when metadata (such as dimensions and duration) is loaded.Event
loadstartThis event occurs when the browser starts looking for the specified media.ProgressEvent
messageThis event occurs when a message is received from the event source.Event
mousedownThis event occurs when the user presses the mouse button over an element.MouseEvent
mouseenterThis event occurs when the pointer moves over an element.MouseEvent
mouseleaveThis event occurs when the pointer moves out of an element.MouseEvent
mousemoveThis event occurs when the pointer moves over an element.MouseEvent
mouseoverThis event occurs when the pointer moves over an element or one of its child elements.MouseEvent
mouseoutThis event occurs when the mouse pointer is moved out of an element or one of its child elements.MouseEvent
mouseupThis event occurs when the user releases the mouse button over an element.MouseEvent
mousewheelNot recommended for use.Switch to the wheel eventWheelEvent
offlineThis event occurs when the browser starts working offline.Event
onlineThis event occurs when the browser starts working online.Event
openThis event occurs when a connection to the event source is opened.Event
pagehideThis event occurs when the user leaves the webpage navigation.PageTransitionEvent
Page displayThis event occurs when the user navigates to a webpage.PageTransitionEvent
pasteThis event occurs when the user pastes some content into an element.ClipboardEvent
pauseThis event occurs when the user or the media is paused programmatically.Event
playThis event occurs when the media starts or is no longer paused.Event
playingThis event occurs when the media is played after pausing or stopping buffering.Event
popstateThis event occurs when the history of the window changes.PopStateEvent
progressThis event occurs when the browser is fetching media data (downloading media) in the process.Event
ratechangeThis event occurs when the playback speed of the media is changed.Event
resizeThis event occurs when the document view size is adjusted.UiEvent, Event
resetThis event occurs when the form is reset.Event
scrollAn event occurs when the user scrolls the scrollbar of a scrollable element.UiEvent, Event
searchThis event occurs when the user enters content in the search field (for <input="search">).Event
seekedWhen the user finishes moving/This event occurs when the user jumps to a new position in the media.Event
seekingWhen the user starts moving/This event occurs when the user jumps to a new position in the media.Event
selectAn event occurs when the user selects some text (for <input> and <textarea>).UiEvent, Event
showThis event occurs when the <menu> element is displayed as a context menuEvent
stalledThis event occurs when the browser tries to fetch media data but the data is not availableEvent
storageThis event occurs when the web storage area is updatedStorageEvent
submitThis event occurs when a form is submittedEvent
suspendThis event occurs when the browser intentionally does not fetch media dataEvent
timeupdateThis event occurs when the playback position changes (e.g., when the user fast-forwards to another point in the media)Event
toggleThis event occurs when the user opens or closes the <details> elementEvent
touchcancelThis event occurs when the touch is interruptedTouchEvent
touchendThis event occurs when a finger is lifted off the touch screenTouchEvent
touchmoveThis event occurs when a finger is dragged on the screenTouchEvent
touchstartThis event occurs when a finger is placed on the touch screenTouchEvent
transitionendThis event occurs when the CSS transition is completedTransitionEvent
unloadThis event occurs when the document or its dependent resources are unloadedUiEvent, Event
volumechangeThis event occurs when the volume of the media has changed (including setting the volume to 'mute')Event
waitingThis event occurs when media has paused but is expected to resume (e.g., media paused to buffer more data)Event
wheelThis event occurs when the mouse wheel scrolls up or down over an elementWheelEvent

HTML DOM Event Properties

The following table lists the properties of DOM events:

PropertiesDescriptionEvent Type
altKeyReturns whether the 'ALT' key was pressed when the mouse event was triggeredMouseEvent
altKeyReturns whether the 'ALT' key was pressed when the key event was triggeredKeyboardEvent, TouchEvent
animationNameReturns the name of the animationAnimationEvent
bubblesReturns whether a specific event is a bubbling eventEvent
buttonReturns the mouse button pressed when the mouse event is triggeredMouseEvent
buttonsReturns the mouse button pressed when the mouse event is triggeredMouseEvent
cancelableReturns whether the event can prevent its default actionEvent
charCodeReturns the Unicode character code of the key that triggered the onkeypress eventKeyboardEvent
changeTouchesReturns a list of all touch objects whose state changed between the last touch and this touchTouchEvent
clientXReturns the horizontal coordinate of the mouse pointer relative to the current window when the mouse event was triggeredMouseEvent, TouchEvent
clientYReturns the vertical coordinate of the mouse pointer relative to the current window when the mouse event was triggeredMouseEvent, TouchEvent
clipboardDataReturns an object that contains the data affected by clipboard operationsClipboardData
codeReturns the code of the key that triggered the eventKeyboardEvent
composedReturns whether the event is composedEvent
ctrlKeyReturns whether the 'CTRL' key was pressed when the mouse event was triggeredMouseEvent
ctrlKeyReturns whether the 'CTRL' key is pressed when the key event is triggeredKeyboardEvent, TouchEvent
currentTargetReturns the element that triggers the event of its event listenerEvent
dataReturns the inserted characterInputEvent
dataTransferReturns an object that contains the data to be dragged and dropped/Data inserted or deletedDragEvent, InputEvent
defaultPreventedReturns whether the preventDefault() method is called for the eventEvent
deltaXReturns the horizontal scroll amount of the mouse wheel (x-axis)WheelEvent
deltaYReturns the vertical scroll amount of the mouse wheel (y-axis)WheelEvent
deltaZReturns the scroll amount of the mouse wheel on the Z-axisWheelEvent
deltaModeReturns a number indicating the unit of measurement for the increment value (pixels, lines, or pages)WheelEvent
detailReturns a number indicating how many times the mouse has been clickedUiEvent
elapsedTimeReturns the number of seconds the animation has runAnimationEvent
elapsedTimeReturns the number of seconds the transition has run 
eventPhaseReturns which stage of the event stream is currently being evaluatedEvent
inputTypeReturns the type of change (i.e., 'insert' or 'delete')InputEvent
isComposingReturns whether the state of the event is being composedInputEvent, KeyboardEvent
isTrustedReturns whether the event is trustedEvent
keyReturns the key value of the key represented by the eventKeyboardEvent
keyReturns the key of the stored item that has been changedStorageEvent
keyCodeReturns the Unicode character code of the key that triggered the onkeypress event, or the Unicode key code of the key that triggered the onkeydown or onkeyup event.KeyboardEvent
locationReturns the position of the key on the keyboard or deviceKeyboardEvent
lengthComputableReturns whether the length of the progress can be calculatedProgressEvent
loadedReturns the amount of work loadedProgressEvent
metaKeyReturns whether the 'META' key is pressed when the event is triggeredMouseEvent
metaKeyReturns whether the 'meta' key is pressed when the key event is triggeredKeyboardEvent, TouchEvent
MovementXReturns the horizontal coordinate of the mouse pointer relative to the position of the last mousemove eventMouseEvent
MovementYReturns the vertical coordinate of the mouse pointer relative to the position of the last mousemove eventMouseEvent
newValueReturns the new value of the stored item that has been changedStorageEvent
newURLReturns the URL of the document after the hash value changeHasChangeEvent
offsetXReturns the horizontal coordinate of the mouse pointer relative to the edge of the target elementMouseEvent
offsetYReturns the vertical coordinate of the mouse pointer relative to the edge of the target elementMouseEvent
oldValueReturns the old value of the stored item that has been changedStorageEvent
oldURLReturns the URL of the document before the hash changeHasChangeEvent
onemptiedThis event occurs when an adverse situation occurs and the media file suddenly becomes unavailable (for example, an unexpected disconnection) 
pageXReturns the horizontal coordinate of the mouse pointer relative to the document when the mouse event was triggeredMouseEvent
pageYReturns the vertical coordinate of the mouse pointer relative to the document when the mouse event was triggeredMouseEvent
persistedReturns whether the web page has been cached by the browserPageTransitionEvent
propertyNameReturns the name of the CSS property associated with the animation or transitionAnimationEvent, TransitionEvent
pseudoElementReturns the name of the pseudo-element associated with the animation or transitionAnimationEvent, TransitionEvent
region
MouseEvent
relatedTargetReturns the element related to the element that triggered the mouse eventMouseEvent
relatedTargetReturns the element related to the element that triggered the eventFocusEvent
repeatReturns whether a key is held down repeatedlyKeyboardEvent
screenXReturns the horizontal coordinate of the mouse pointer relative to the screen when the event was triggeredMouseEvent
screenYReturns the vertical coordinate of the mouse pointer relative to the screen when the event was triggeredMouseEvent
shiftKeyReturns whether the 'SHIFT' key was pressed when the event was triggeredMouseEvent
shiftKeyReturns whether the 'SHIFT' key was pressed when the key event was triggeredKeyboardEvent, TouchEvent
stateReturns an object containing a copy of the history entryPopStateEvent
storageAreaReturns an object representing the affected storage objectStorageEvent
targetReturns the element that triggered the eventEvent
targetTouchesReturns a list of all touch objects in contact with the surface and on the target element where the touchstart event occurred, which is the same as the current target elementTouchEvent
timeStampReturns the time at which the event was created (in milliseconds relative to the epoch)Event
totalReturns the total amount of work to be loadedProgressEvent
touchesReturns a list of all touch objects currently in contact with the surfaceTouchEvent
transitionendThis event occurs when the CSS transition is completedTransitionEvent
typeReturns the name of the eventEvent
urlReturns the URL of the document whose items have been changedStorageEvent
whichReturns the mouse button pressed when the mouse event is triggeredMouseEvent
whichReturns the Unicode character code of the key that triggered the onkeypress event, or the Unicode key code of the key that triggered the onkeydown or onkeyup event.KeyboardEvent
viewReturns a reference to the Window object where the event occurredUiEvent

HTML DOM Event Methods

The following table lists the methods of DOM events:

MethodDescriptionEvent Type
createEvent()Create a new eventEvent
getTargetRanges()Returns an array containing the target range that will be affected by the insertion/Impact of deletionInputEvent
getModifierState()Returns an array containing the target range that will be affected by the insertion/Impact of deletionMouseEvent
preventDefault()Prevent the browser from executing the default action of the selected elementEvent
stopImmediatePropagation()Prevent other listeners for the same event from being calledEvent
stopPropagation()Prevent further propagation of the event in the event flowEvent

Related References

Javascript Tutorial:Javascript Events

Javascript Tutorial:Event Listener

Javascript Tutorial:Event Propagation