WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

HTML Event Attributes


Global Event Attributes

HTML 4 added the ability to let events trigger actions in a browser, like starting a JavaScript when a user clicks on an element.

To learn more about programming events, please visit our JavaScript tutorial.

Below are the global event attributes that can be added to HTML elements to define event actions.

= New event attributes in HTML5.


Window Event Attributes

Events triggered for the window object (applies to the <body> tag):

Attribute Value Description
onafterprint script Script to be run after the document is printed
onbeforeprint script Script to be run before the document is printed
onbeforeunload script Script to be run when the document is about to be unloaded
onerror script Script to be run when an error occurs
onhashchange script Script to be run when there has been changes to the anchor part of the a URL
onload script Fires after the page is finished loading
onmessage script Script to be run when the message is triggered
onoffline script Script to be run when the browser starts to work offline
ononline script Script to be run when the browser starts to work online
onpagehide script Script to be run when a user navigates away from a page
onpageshow script Script to be run when a user navigates to a page
onpopstate script Script to be run when the window's history changes
onresize script Fires when the browser window is resized
onstorage script Script to be run when a Web Storage area is updated
onunload script Fires once a page has unloaded (or the browser window has been closed)

Form Events

Events triggered by actions inside a HTML form (applies to almost all HTML elements, but is most used in form elements):

Attribute Value Description
onblur script Fires the moment that the element loses focus
onchange script Fires the moment when the value of the element is changed
oncontextmenu script Script to be run when a context menu is triggered
onfocus script Fires the moment when the element gets focus
oninput script Script to be run when an element gets user input
oninvalid script Script to be run when an element is invalid
onreset script Fires when the Reset button in a form is clicked
onsearch script Fires when the user writes something in a search field (for <input="search">)
onselect script Fires after some text has been selected in an element
onsubmit script Fires when a form is submitted

Keyboard Events

Attribute Value Description
onkeydown script Fires when a user is pressing a key
onkeypress script Fires when a user presses a key
onkeyup script Fires when a user releases a key

Mouse Events

Events activated by a mouse, or comparable client actions:

Attribute Value Description
onclick script Fires on a mouse click on the element
ondblclick script Fires on a mouse double tap on the element
ondrag script Script to be run when a component is dragged
ondragend script Script to be kept running toward the finish of a drag operation
ondragenter script Script to be run when a component has been hauled to a legitimate drop target
ondragleave script Script to be run when a component leaves a legitimate drop target
ondragover script Script to be run when a component is being hauled over a legitimate drop target
ondragstart script Script to be kept running toward the beginning of a drag operation
ondrop script Script to be run when hauled component is being dropped
onmousedown script Fires when a mouse catch is pushed down on an element
onmousemove script Fires when the mouse pointer is moving while it is over an element
onmouseout script Fires when the mouse pointer moves out of an element
onmouseover script Fires when the mouse pointer moves over an element
onmouseup script Fires when a mouse catch is discharged over an element
onmousewheel script Deprecated. Use the onwheel trait instead
onscroll script Script to be run when a component's scrollbar is being scrolled
onwheel script Fires when the mouse wheel moves up or down over an element

Clipboard Events

Attribute Value Description
oncopy script Fires when the client duplicates the substance of an element
oncut script Fires when the client cuts the substance of an element
onpaste script Fires when the client glues some substance in an element

Media Events

Events activated by medias like recordings, pictures and sound (applies to all HTML components, yet is most regular in media components, like <audio>, <embed>, <img>, <object>, and <video>).

Tip: Look at our HTML Audio and Video DOM Reference for more information.

Attribute Value Description
onabort script Script to be kept running on abort
oncanplay script Script to be run when a record is prepared to begin playing (when it has sufficiently cushioned to begin)
oncanplaythrough script Script to be run when a record can be played the whole distance as far as possible without delaying for buffering
oncuechange script Script to be run when the sign changes in a <track> component
ondurationchange script Script to be run when the length of the media changes
onemptied script Script to be run when something awful occurs and the record is all of a sudden inaccessible (like out of the blue disconnects)
onended script Script to be run when the media has achieve the end (a valuable occasion for messages like "thanks for listening")
onerror script Script to be run when a mistake happens when the record is being stacked
onloadeddata script Script to be run when media information is loaded
onloadedmetadata script Script to be run when meta information (like measurements and term) are loaded
onloadstart script Script to be run similarly as the record stacks before anything is really loaded
onpause script Script to be run when the media is stopped either by the client or programmatically
onplay script Script to be run when the media is prepared to begin playing
onplaying script Script to be run when the media really has begun playing
onprogress script Script to be run when the program is getting the media data
onratechange script Script to be run each time the playback rate changes (like when a client changes to a moderate movement or quick forward mode)
onseeked script Script to be run when the looking for credit is set to false showing that looking for has ended
onseeking script Script to be run when the looking for credit is set to genuine showing that looking for is active
onstalled script Script to be run when the program can't bring the media information for whatever reason
onsuspend script Script to be run while getting the media information is halted before it is totally stacked for whatever reason
ontimeupdate script Script to be run when the playing position has changed (like when the client quick advances to an alternate point in the media)
onvolumechange script Script to be run each time the volume is changed which (incorporates setting the volume to "mute")
onwaiting script Script to be run when the media has delayed however is relied upon to continue (like when the media stops to support more data)

Misc Events

Attribute Value Description
onerror script Fires when a mistake happens while stacking an outside file
onshow script Fires when a <menu> component is appeared as a setting menu
ontoggle script Fires when the client opens or shuts the <details> element