Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Knowledge base

Knowledge base

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

Entries: 5788

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
HTML

onemptied — handle a media resource being emptied

The onemptied attribute specifies JavaScript to run when an emptied event occurs. For audio and video, this event concerns resetting the media resource state, rather than ordinary completion of playback.

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

onended — handling the end of playback

The onended attribute contains JavaScript executed when an ended event is received. On audio and video elements, it responds to reaching the end of the media, rather than simply pausing playback.

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

onerror — handling an error event

The onerror attribute contains JavaScript that handles an error event, for example when an image fails to load. Element handlers differ from window.onerror in their arguments and in the meaning of their return value.

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

onfocus — handling focus acquisition

The onfocus attribute contains JavaScript executed when a focus event is received. It lets you respond when an input gains focus, but does not itself make an element focusable.

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

onformdata — handling form data construction

The onformdata attribute defines a handler for the formdata event. It lets you inspect and modify form data after the entry list has been constructed, both during form submission and when new FormData(form) is called.

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

onhashchange — handling URL fragment changes

The onhashchange attribute on body specifies JavaScript that handles the Window object's hashchange event. It lets a page respond to same-document navigation when the URL fragment, the portion after #, changes.

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

oninput — handling the input event

The oninput attribute contains JavaScript that runs for the input event. On a text field, it lets you respond to user edits without waiting for the user to leave the field.

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

oninvalid — handling failed validation

The oninvalid attribute contains JavaScript that handles the invalid event when a checked control fails form constraints. It does not automatically run on every keystroke.

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