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.
CKTIS / Knowledge base
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
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.
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.
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.
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.
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.
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.
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.
The ondblclick attribute contains JavaScript that handles the dblclick event, typically triggered by a double-click. It can be used on all HTML elements.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.