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

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
HTML

onkeydown — handling a key press

The onkeydown attribute contains JavaScript code that handles the keydown event. It lets you respond to a key press; the event object provides event data. It is not a Boolean attribute.

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

onkeypress — keypress event handler attribute

The global HTML attribute onkeypress contains JavaScript code that handles the keypress event. The attribute name includes the on prefix; the event name does not.

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

onkeyup — handling key release

The onkeyup attribute contains JavaScript that handles the keyup event after a key is released. It is an HTML global attribute, not a way to detect every change to a field's value.

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

onlanguagechange — handling preferred-language changes

The onlanguagechange attribute on body sets the Window object's handler for languagechange. The event signals a change in the user's preferred languages as understood by the browser, rather than a change to the document's lang attribute.

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

onload — handling the load event

The onload attribute contains JavaScript that handles the load event. On the body element, it concerns page loading and handles the Window object's event rather than an event on body itself.

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

onloadeddata — handling available media data

The onloadeddata attribute runs code for the loadeddata event when data for the current audio or video playback position first becomes available. It does not mean the entire file has downloaded or playback has started.

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

onloadedmetadata — handling media metadata loading

The onloadedmetadata attribute contains JavaScript that handles the loadedmetadata event, usually on audio or video. It signals metadata availability, not completion of the download or readiness for uninterrupted playback.

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

onloadstart — handling the start of media loading

The onloadstart attribute specifies JavaScript that handles the loadstart event. For audio and video elements, this event signals the start of looking for media data, not completion of the download or readiness to play.

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

onmessage — handling window messages

The onmessage attribute on body sets the Window object's message event handler. It receives messages sent through postMessage, among other uses; check the sender and payload before using received data.

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

onmessageerror — handling message deserialization failure

The onmessageerror attribute on body sets the Window object's messageerror handler. The event signals failure to deserialize an incoming message, rather than an arbitrary communication error.

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

onmousedown — mouse-button press handler attribute

The onmousedown attribute assigns JavaScript code to an HTML element to handle the mousedown event. It responds to a mouse-button press rather than waiting for a completed click.

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

onmouseenter — handling mouse pointer entry

The global HTML attribute onmouseenter specifies JavaScript to run for the mouseenter event when the mouse pointer enters an element.

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

onmouseleave — handling the mouse leaving an element

The global HTML onmouseleave attribute contains JavaScript that handles the mouseleave event. It lets an element respond when the mouse pointer leaves the element and its descendants.

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

onmousemove — handling mouse movement

The global HTML attribute onmousemove contains JavaScript that handles the mousemove event. The example dispatches it programmatically so the result does not depend on mouse movement.

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

onmouseout — handling a mouse leaving an element

The global onmouseout attribute contains JavaScript code that handles the mouseout event. Use it to respond when the mouse pointer leaves an element.

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

onmouseover — handling pointer entry

The onmouseover attribute contains JavaScript that handles the mouseover event. It can react when the pointer enters an element, but it does not replace keyboard support and can also handle events originating from descendants.

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