Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

Knowledge base — HTML

Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.

Entries: 397

HTML

onbeforeunload — handle an event before leaving a page

The onbeforeunload attribute on body sets a handler for the Window object's beforeunload event. It can request a warning before leaving the page, but it guarantees neither a dialog nor cancellation of navigation.

Intermediate · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

onblur — handling loss of focus

The onblur attribute contains JavaScript that runs for the blur event when an element loses focus. It lets you respond to leaving a field regardless of whether the user changed its value.

Basic · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

oncancel — handling the cancel event

The oncancel attribute contains code that runs when a cancel event is received. On a dialog element, it lets you respond to a close request and, when the event is cancelable, prevent closing.

Basic · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

oncanplay — handling media readiness for playback

The oncanplay attribute contains JavaScript that runs for the canplay event. For audio and video, this signals readiness to start or resume playback, but does not guarantee that the entire resource can play without buffering interruptions.

Basic · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

oncanplaythrough — handling estimated media readiness

The oncanplaythrough attribute contains JavaScript that handles the canplaythrough event. For audio and video, this signals an estimated ability to play through to the end without further buffering, not a guarantee of uninterrupted playback.

Basic · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

onchange — handling a change event

The onchange attribute contains JavaScript that runs for a change event. For form controls, this represents a committed user change, not necessarily every edit to the value.

Basic · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

The onclick attribute

The onclick attribute contains JavaScript that handles a click event. Distinguish it from the element.onclick property.

Basic · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

onclose — handling a close event

The onclose attribute contains JavaScript that handles the close event. A typical use is responding when a dialog element closes, for example by reading its returnValue. It is not a mechanism for preventing closure.

Basic · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

oncommand — handling the command event

The oncommand attribute specifies JavaScript to execute when a command event is received. It belongs on the element receiving the command; it neither selects the target nor initiates a command by itself.

Intermediate · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

oncontextlost — handling canvas context loss

The oncontextlost attribute specifies code that handles contextlost, dispatched when a canvas element's 2D rendering context is lost. It lets an application react to resource loss but does not restore the drawing itself.

Intermediate · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

oncontextmenu — context menu event handler

The oncontextmenu attribute specifies JavaScript that handles the contextmenu event. It is available on all HTML elements; returning false cancels the event if it is cancelable.

Basic · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

oncontextrestored — handling canvas context restoration

The oncontextrestored attribute specifies code for handling the contextrestored event. For a canvas with a 2D context, the event signals restoration after context loss; the application should then rebuild its drawing settings and content.

Intermediate · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

oncopy — copy event handler

The oncopy attribute assigns JavaScript code to handle the copy event. It can appear on any HTML element to react to copying, for example by updating a message on the page.

Basic · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

oncuechange — handle changes to active text-track cues

The oncuechange attribute specifies code to run for cuechange events when timed text-track cues become active or stop being active. A JavaScript property with the same name is also available on TextTrack objects.

Intermediate · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

oncut — handling the cut event

The oncut attribute contains JavaScript that handles the cut event. It can appear on any HTML element; in the example, it updates a status message and cancels the default cut action.

Basic · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

ondblclick — handling a double-click

The ondblclick attribute contains JavaScript that handles the dblclick event, typically triggered by a double-click. It can be used on all HTML elements.

Basic · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

ondrag — handle dragging events

The ondrag attribute contains JavaScript that handles the drag event, dispatched repeatedly at the source during dragging. The attribute does not itself make an element draggable or define a drop target.

Basic · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

ondragend — handling the end of a drag

The ondragend attribute runs JavaScript when a drag operation ends, including cancellation or an unsuccessful drop. It is useful for cleaning up the source element's state, not for confirming that a target accepted data.

Basic · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

ondragenter — handling entry of a dragged item

The ondragenter attribute defines JavaScript that runs for the dragenter event when a dragged item enters a target element. It lets the target react to entry but does not handle the drop itself.

Basic · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

ondragleave — handling departure from a drag target

The ondragleave attribute contains JavaScript that handles the dragleave event. It can, for example, remove highlighting from the previous target during a drag; it does not mean that the entire drag operation has ended.

Basic · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

ondragover — handling dragging over an element

The ondragover attribute contains JavaScript that handles dragover events while a drag is over a target. Canceling the event with event.preventDefault() allows an ordinary element to participate in accepting a drop.

Intermediate · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

ondragstart — handle the start of dragging

The ondragstart attribute defines JavaScript that runs for the dragstart event when dragging begins. It can prepare the operation's data or cancel its initiation; it does not itself make an element draggable.

Basic · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

ondrop — handling dropped data

The ondrop attribute defines JavaScript that handles the drop event during drag and drop. It does not create a drop target by itself: the default handling of dragover usually needs to be canceled as well.

Basic · WHATWG HTML Living Standard; index snapshot date recorded separately
HTML

ondurationchange — handling media duration changes

The ondurationchange attribute contains JavaScript executed for the durationchange event. It typically updates duration information for audio and video elements; it does not report ongoing playback progress.

Basic · WHATWG HTML Living Standard; index snapshot date recorded separately