HTML Event Attributes

When a user action causes a browser reaction, then this is called an event. There are a lot of event attributes available in HTML5. These are discussed below.

Windows Event Attributes:

Windows events are applied to the <body> tag to trigger events for the window object. Listed below are the HTML Windows event attributes.

Attribute Value Description
onafterprint script Runs the script after the document is printed.
onbeforeprint script Runs the script before the document is printed.
onbeforeunload script Runs the script before a document is unloaded.
onerror script Runs the script when an error occurs.
onhashchange script Runs the script when the anchor part in the URL of the webpage is changed.
onload script Runs the script when the webpage is entirely loaded.
onmessage script Runs the script when a message event occurs.
onoffline script Runs the script when the browser starts working offline.
ononline script Runs the script when the browser starts working online.
onpagehide script Runs the script when the user has moved away from the current webpage.
onpageshow script Runs the script when the current webpage is focused.
onpopstate script Runs the script when the window’s active history is changed.
onresize script Runs the script when the window is resized.
onstorage script Runs the script when web storage is updated.
onunload script Runs the script when the current webpage is unloaded, or the browser window is closed.

Form Event Attributes:

Form Events are applied to almost all HTML elements and are mostly used in form elements to trigger events by actions inside an HTML form. Listed below are the HTML form event attributes.

Attribute Value Description
onblur script Runs the script when the form element loses focus.
onchange script Runs the script when the value of the element is changed.
onfocus script Runs the script when the element gets focused.
oninput script Runs the script when the user enters input to the element.
oninvalid script Runs the script when the element does not satisfy its predefined constraints.
onreset script Runs the script when the user resets the form element values.
onsearch script Runs the script when a search field receives some input.
onselect script Runs the script when the user has selected some text.
onsubmit script Runs the script when a form is submitted.

Keyboard Event Attributes:

Keyboard Events are used to trigger events by actions caused by a keyboard. Listed below are the HTML keyboard event attributes.

Attribute Value Description
onkeydown script Executes the script when the user is pressing a key on the keyboard.
onkeypress script Executes the script when the user presses a key on the keyboard.
onkeyup script Executes the script when the user releases the pressed key of the keyboard.

Mouse Event Attributes:

Listed below are the HTML mouse event attributes.

Attribute Value Description
onclick script Runs the script when the mouse clicks on the element.
ondblclick script Runs the script when a mouse double-click occurs on the element.
onmousedown script Runs the script when the mouse button is pressed on the element.
onmousemove script Runs the script when the mouse pointer moves over the element.
onmouseout script Runs the script when the mouse moves outside the element.
onmouseover script Runs the script when the mouse moves onto the element.
onmouseup script Runs the script when the mouse button is released.
onmousewheel script Deprecated.
onwheel script Runs the script when the mouse wheel rolls up or down over the element.

Clipboard Event Attributes:

Listed below are the HTML clipboard event attributes.

Attribute Value Description
oncopy script Executes the script when the user copies the content of an element.
oncut script Executes the script when the user cuts the content of an element.
onpaste script Executes the script when the user pastes some content in an element.

Media Event Attributes:

Listed below are the HTML media event attributes.

Attribute Value Description
onabort script Event triggers when media playback is aborted.
oncanplay script The event triggers when the media file is ready to play.
oncanplaythrough script Event triggers when the media file is ready to play without buffering or stopping.
oncuechange script Event triggers when the cue of <track> element is changed.
ondurationchange script Event triggers when the media file duration is changed.
onemptied script Event triggers if media occurs some fatal error, and the file becomes unavailable.
onended script Event triggers when the media file occurs at its endpoint.
onerror script Event triggers when some error occurs while fetching the media data.
onloadeddata script Event triggers when media data is loaded.
onloadedmetadata script Event triggers when metadata of media file is loaded.
onloadstart script Event triggers when loading of media file starts.
onpause script The event triggers when media playback is paused.
onplay script The event triggers when the media file is ready to play after being paused.
onplaying script Event triggers when a media file is started playing.
onprogress script Event triggers when the browser is in the process of getting the media data.
onratechange script Event triggers when playback speed changes.
onseeked script Event triggers when the seek operation is ended and the seeking attribute is set to false.
onseeking script Event triggers when seeking operation active and seeking attribute is set to true.
onstalled script The event triggers when the browser unexpectedly stops fetching the data media.
onsuspend script Event triggers if fetching of media data is intentionally stopped.
ontimeupdate script Event triggers when the playback position is changed, such as if a user fasts forward the track.
onvolumechange script Event triggers when media volume is changed (muted or unmuted).
onwaiting script Event triggers if playback pauses to wait for loading more data.

 

Please follow and like us:
Content Protection by DMCA.com