Login

Username:

Password: 

Join us Now |  Forgot Password? | Forgot UserName?

HTML

Learn step by step



HTML5 Events

A site visitor may click on links, mouseover on a element. These are examples of what JavaScript calls events.

We can write our own event handlers and can be invoked using Javascript or VBScript. Below are the event specification for HTML5:

For now we would be covering element specific events and will cover it in detail in next chapters.

Window Event Attributes

Events triggered by window object (applies to the &1t;body> tag):

Attribute Value Description
onafterprint script Event to be triggered post document is printed
onbeforeprint script Event triggered before document is printed
onbeforeunload script Event before document is unloaded
onerror script Event to handle error
onhaschange script Event triggered when there is change in document
onload script Event triggered post window is loaded
onmessage script Event triggered when message received
onoffline script Event triggered when document goes offline
ononline script Event triggered when document goes online
onpagehide script Event triggered when window is hidden
onpageshow script Event triggered when window becomes visible
onpopstate script Event triggered when document history changes
onredo script Event triggered when document redo done
onresize script Event triggered on resize of browser/window
onstorage script SEvent triggered when a Web Storage area is updated
onundo script Event triggered when the document performs an undo
onunload script Event triggered when document is unloaded or window closed
Form Events

Events triggered within HTML forms(applies to almost all HTML elements, but mostly used in form elements):

Attribute Value Description
onblur script Trigger when control looses focus from the element
onchange script Triggers when element value changes
oncontextmenu script Triggers when context menu invoked via right click or any shortcut key
onfocus script Triggers when control is passed on to element
onformchange script Event triggered on form change
oninput script Event triggered when an element gets user input
onforminput script Event triggered when form gets user input
oninvalid script Event triggered if element value is invalid
onselect script Event triggered on selection of a value from element like dropdown
onreset script Event triggered when reset button in form is clicked
Not supported in HTML5
onsubmit script Event triggered on submission of form
Keyboard Events
Attribute Value Description
onkeydown script Event triggered when a user is pressing a key
onkeypress script Event triggered when a user presses a key
onkeyup script Event triggered when a user releases a key
Mouse Events

Events related to mouse:

Attribute Value Description
onclick script Event triggered on mouse single click
ondblclick script Event triggered on mouse double click
ondrag script Event triggered when an element is dragged
ondragend script Event triggered when element dragging ends
ondragenter script Event triggered when an element has been dragged to a valid drop target
ondragleave script Event triggered when an element leaves a valid drop target
ondragover script Event triggered when an element is being dragged over a valid drop target
ondragstart script Event triggered at the start of a drag operation
ondrop script Event triggered when dragged element is being dropped
onmousedown script Event triggered on mouse button press
onmousemove script Event triggered when the mouse pointer rolls over an element
onmouseout script Event triggered when the mouse pointer moves out of an element
onmouseover script Event triggered when the mouse pointer moves over an element
onmouseup script Event triggered when a mouse button is released over an element
onmousewheel script Event triggered when the mouse wheel is being rotated
onscroll script Event triggered when element's scrollbar is being scrolled
Media Events

Events triggered by medias like audio, video, images (it applies for all HTML elements, but most common in media elements, like &1t;audio>, &1t;embed>, &1t;img>, &1t;object>, and &1t;video>):

Attribute Value Description
onabort script Event triggered on abort
oncanplay script Event triggered when a file is ready to start playing (when it has buffered enough to begin)
oncanplaythrough script Event triggered when a file can be played all the way to the end without pausing for buffering
ondurationchange script Event triggered when the length of the media changes
onemptied script Event triggered when something bad happens and the file is suddenly unavailable (like unexpectedly disconnects)
onended script Event triggered when the media reaches end (a useful event for messages like "feedback for video")
onerror script Event triggered when an error occurs when the file is being loaded
onloadeddata script Event triggered when media data is loaded
onloadedmetadata script Event triggered when meta data (like duration and dimensions) are loaded
onloadstart script Event triggered when media starts loading
onpause script Event triggered when the media is paused either by the user or programmatically
onplay script Event triggered when the media is ready for play
onplaying script Event triggered when the media starts playing
onprogress script Event triggered when the browser is getting the media data
onratechange script Event triggered each time the playback rate changes (like when a user switches to a slow motion or rewind mode)
onreadystatechange script Event triggered each time the ready state changes (the ready state provides the state of the media data)
onseeked script Event triggered when the seeking has ended
onseeking script Event triggered when the seeking is active
onstalled script Event triggered when the browser is unable to fetch the media data
onsuspend script Event triggered when fetching the media data is stopped before it is completely loaded
ontimeupdate script Script to be run when the playing position has changed (like when the user fast forwards to a different point in the media)
onvolumechange script Event triggered each time media volume is changed (includes setting the volume to "mute")
onwaiting script Event triggered when the media has paused or waits for media content (like when the media pauses to buffer more data)


Related Videos