HTML - Events Reference


Advertisements

When users visit your website, they do things like click various links, bring mouse over text and images etc. These are examples of what we call events in JavaScript and VBScript terminologies.

We can write our event handlers using JavaScript or VBScript and can specify some actions to be taken against these events. Though these are the events but they will be specified as attributes for the HTML tags.

The HTML 4.01 specification had defined 19 events but later HTML-5 has added many other events which we have listed down here −

Window Events Attributes

Following events have been introduced in older versions of HTML but all the tags marked with HTML-5are part of HTML-5.

Events HTML-5 Description
onafterprint HTML-5 Triggers after a document is printed
onbeforeprint HTML-5 Triggers before a document is printed
onbeforeonload HTML-5 Triggers before a document loads
onerror HTML-5 Triggers when an error occurs
onhaschange HTML-5 Triggers when a document has changed
onload Triggers when a document loads
onmessage HTML-5 Triggers when a message is triggered
onoffline HTML-5 Triggers when a document goes offline
ononline HTML-5 Triggers when a document comes online
onpagehide HTML-5 Triggers when a window is hidden
onpageshow HTML-5 Triggers when a window becomes visible
onpopstate HTML-5 Triggers when a window's history changes
onredo HTML-5 Triggers when a document performs a redo
onresize HTML-5 Triggers when a window is resized
onstorage HTML-5 Triggers when a document loads
onundo HTML-5 Triggers when a document performs an undo
onunload Triggers when a user leaves the document

Form Events

Following tags have been introduced in older versions of HTML but all the tags marked with HTML-5 are part of HTML-5.

Events HTML-5 Description
onblur Triggers when a window loses focus
onchange Triggers when an element changes
oncontextmenu HTML-5 Triggers when a context menu is triggered
onfocus Triggers when a window gets focus
onformchange HTML-5 Triggers when a form changes
onforminput HTML-5 Triggers when a form gets user input
oninput HTML-5 Triggers when an element gets user input
oninvalid HTML-5 Triggers when an element is invalid
onreset Triggers when a form is reset
onselect Triggers when an element is selected
onsubmit Triggers when a form is submitted

Keyboard Events

Events HTML-5 Description
onkeydown Triggers when a key is pressed
onkeypress Triggers when a key is pressed and released
onkeyup Triggers when a key is released

Mouse Events

Following tags have been introduced in older versions of HTML but all the tags marked with HTML-5 are part of HTML-5.

Events HTML-5 Description
onclick Triggers on a mouse click
ondblclick Triggers on a mouse double-click
ondrag HTML-5 Triggers when an element is dragged
ondragend HTML-5 Triggers at the end of a drag operation
ondragenter HTML-5 Triggers when an element has been dragged to a valid drop target
ondragleave HTML-5 Triggers when an element leaves a valid drop target
ondragover HTML-5 Triggers when an element is being dragged over a valid drop target
ondragstart HTML-5 Triggers at the start of a drag operation
ondrop HTML-5 Triggers when a dragged element is being dropped
onmousedown Triggers when a mouse button is pressed
onmousemove Triggers when the mouse pointer moves
onmouseout Triggers when the mouse pointer moves out of an element
onmouseover Triggers when the mouse pointer moves over an element
onmouseup   Triggers when a mouse button is released
onmousewheel HTML-5 Triggers when the mouse wheel is being rotated
onscroll HTML-5 Triggers when an element's scrollbar is being scrolled

Media Events

Following tags have been introduced in older versions of HTML but all the tags marked with HTML-5 are part of HTML-5.

Events HTML-5 Description
onabort Triggers on an abort event
oncanplay HTML-5 Triggers when a media can start play, but might has to stop for buffering
oncanplaythrough HTML-5 Triggers when a media can be played to the end, without stopping for buffering
ondurationchange HTML-5 Triggers when the length of a media is changed
onemptied HTML-5 Triggers when a media resource element suddenly becomes empty.
onended HTML-5 Triggers when a media has reached the end
onerror HTML-5 Triggers when an error occurs
onloadeddata HTML-5 Triggers when media data is loaded
onloadedmetadata HTML-5 Triggers when the duration and other media data of a media element is loaded
onloadstart HTML-5 Triggers when the browser starts loading the media data
onpause HTML-5 Triggers when media data is paused
onplay HTML-5 Triggers when media data is going to start playing
onplaying HTML-5 Triggers when media data has started playing
onprogress HTML-5 Triggers when the browser is fetching the media data
onratechange HTML-5 Triggers when the playing rate of media data has changed
onreadystatechange HTML-5 Triggers when the ready-state changes
onseeked HTML-5 Triggers when the seeking attribute of a media element is no longer true, and the seeking has ended
onseeking HTML-5 Triggers when the seeking attribute of a media element is true, and the seeking has begun
onstalled HTML-5 Triggers when there is an error in fetching media data
onsuspend HTML-5 Triggers when the browser has been fetching media data, but stopped before the entire media file was fetched
ontimeupdate HTML-5 Triggers when media changes its playing position
onvolumechange HTML-5 Triggers when a media changes the volume, also when volume is set to "mute"
onwaiting HTML-5 Triggers when media has stopped playing, but is expected to resume
Advertisements