HTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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 separatelyHTMLThe 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