Advertisement

HTML Event Attributes

Global event properties

HTML 4 adds the ability to make the event trigger actions in the browser, such as to enable JavaScript when the user clicks the element when.

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

Listed below are added to the HTML elements to define event actions global event properties.

= HTML5 new event properties.

Event Properties Window

Window object for the event triggered (applied to the <body> tag):

Attributes value description
onafterprint script The script is run after the printed document.
onbeforeprint script Script before the document print runs.
onbeforeunload script Documents before running the uninstall script.
onerror script Scripts that run when an error occurs.
onhaschange script When the script runs when the document has been changed.
onload script Trigger the end of the page is loaded.
onmessage script Scripts that run when the message is triggered.
onoffline script When the script runs when the document is offline.
ononline script When the script runs when the document is on the line.
onpagehide script When the script runs when the window is hidden.
onpageshow script When the script runs when the window becomes visible.
onpopstate script Scripts that run when the window to change history.
onredo script Scripts that run when the document is executed revocation (redo) time.
onresize script Fires when the browser window is resized.
onstorage script Script after the Web Storage area update operation.
onundo script In undo scripts that run when the document execution.
onunload script Once the page has been downloaded trigger (or the browser window has been closed).

Form Events

HTML form within the event action triggered (applies to almost all HTML elements, but the most common element in the form):

Attributes value description
onblur script Script runs when the element loses focus.
onchange script Scripts that run when the element value is changed.
oncontextmenu script When the script is run when the context menu is triggered.
onfocus script When the script is run when the element loses focus.
onformchange script Scripts that run when the form is changed.
onforminput script When the form to get a script to run when the user input.
oninput script When the script is run when the element gets user input.
oninvalid script When the script runs when the element is not valid.
onreset script Triggered when the form of the reset button is clicked. HTML5 is not supported.
onselect script Chinese elements in this trigger after being selected.
onsubmit script Fired when the form is submitted.

Keyboard events

Attributes value description
onkeydown script Fired when the user presses a key.
onkeypress script Fires when the user clicks the button.
onkeyup script Fires when the user releases the button.

Mouse events

By a mouse or similar user actions trigger events:

Attributes value description
onclick script Fires when the mouse clicks on the element.
ondblclick script Double-click the mouse on the element when the trigger occurs.
ondrag script Element is a script that runs when you drag.
ondragend script At the end of a drag operation to run the script.
ondragenter script When the elements of the element has been dragged to a valid drop scripts that run when area.
ondragleave script When the element left scripts that run when a valid drop target.
ondragover script Scripts that run when the element on a valid drop target being dragged.
ondragstart script In the beginning of a drag operation to run the script.
ondrop script Scripts that run when dragged element is being dragged and dropped.
onmousedown script Fires when the mouse button is pressed over an element.
onmousemove script Fires when the mouse pointer moves to the elements.
onmouseout script Fires when the mouse pointer moves out of the element.
onmouseover script Fires when the mouse pointer moves to the elements.
onmouseup script Fires when the mouse button is released over an element.
onmousewheel script Scripts that run when the mouse wheel is being scrolled.
onscroll script When the script runs when the element scroll bar is scrolled.

Media Event

Event-media (such as video, images and audio) triggered (applies to all HTML elements, but is common in media elements, such as <audio>, <embed>, <img>, <object> and <video>):

Attributes value description
onabort script Scripts that run when you exit.
oncanplay script Scripts that run when the file is ready to start playing (at the beginning of the buffer is sufficient).
oncanplaythrough script When the media do not need to be able to play due to a buffer stop script that runs to the end of time.
ondurationchange script When the script runs when the medium length change.
onemptied script Scripts that run when suddenly fails and the file is not available (such as when accidentally disconnected).
onended script Scripts that run when the media has reached the end (you can send something like "Thank you for watching" like the message).
onerror script Scripts that run when an error occurs during the file load.
onloadeddata script When the script is run when media data has been loaded.
onloadedmetadata script Scripts that run when the metadata (such as resolution and duration) is loaded.
onloadstart script In the beginning of the file to load and no load the script before any actual data run.
onpause script Scripts that run when the media is suspended user or program.
onplay script When the media is ready scripts that run when you can start playing.
onplaying script When the script runs when the media started to play.
onprogress script Scripts that run when the browser is to obtain media data.
onratechange script Whenever the scripts that run when the playback rate changes (such as when the user switches to slow motion or fast forward mode).
onreadystatechange script Script (ready state media monitoring data state) operation whenever the ready state changes.
onseeked script Scripts that run when seeking property is set to false (indicating the alignment has been completed) when.
onseeking script Scripts that run when seeking property is set to true (indicating position is active).
onstalled script In the script browser running time for whatever reason could not retrieve media data.
onsuspend script Scripts that run when the termination for whatever reason to retrieve media data in the media before the data is fully loaded.
ontimeupdate script When playing position changes (such as when the user fast-forward to the media in a different location) script to run.
onvolumechange script Whenever the volume change (including the volume is set to silent) when the script runs.
onwaiting script When the media has stopped playing, but intends to continue playing (for example, when the media pause to buffer more data) to run the script