DOM event
DOM Events are a signal that something has occurred, or is occurring, and can be triggered by user interactions or by the browser. Client-side scripting languages like JavaScript, JScript, VBScript, and Java can register various event handlers or listeners on the element nodes inside a DOM tree, such as in HTML, XHTML, XUL, and SVG documents.
Examples of DOM Events:
- When a user clicks the mouse
- When a web page has loaded
- When an image has been loaded
- When the mouse moves over an element
- When an input field is changed
- When an HTML form is submitted
- When a user presses a key
Events
HTML events
Common events
There is a huge collection of events that can be generated by most element nodes:- Mouse events.
- Keyboard events.
- HTML frame/object events.
- HTML form events.
- User interface events.
- Mutation events.
- Progress events.
| Category | Type | Attribute | Description | Bubbles | Cancelable |
| Mouse | click | onclick | Fires when the pointing device button is clicked over an element. A click is defined as a mousedown and mouseup over the same screen location. The sequence of these events is:
| ||
| Mouse | dblclick | ondblclick | Fires when the pointing device button is double-clicked over an element | ||
| Mouse | mousedown | onmousedown | Fires when the pointing device button is pressed over an element | ||
| Mouse | mouseup | onmouseup | Fires when the pointing device button is released over an element | ||
| Mouse | mouseover | onmouseover | Fires when the pointing device is moved onto an element | ||
| Mouse | mousemove | onmousemove | Fires when the pointing device is moved while it is over an element | ||
| Mouse | mouseout | onmouseout | Fires when the pointing device is moved away from an element | ||
| Mouse | dragstart | ondragstart | Fired on an element when a drag is started. | ||
| Mouse | drag | ondrag | This event is fired at the source of the drag, that is, the element where dragstart was fired, during the drag operation. | ||
| Mouse | dragenter | ondragenter | Fired when the mouse is first moved over an element while a drag is occurring. | ||
| Mouse | dragleave | ondragleave | This event is fired when the mouse leaves an element while a drag is occurring. | ||
| Mouse | dragover | ondragover | This event is fired as the mouse is moved over an element when a drag is occurring. | ||
| Mouse | drop | ondrop | The drop event is fired on the element where the drop occurs at the end of the drag operation. | ||
| Mouse | dragend | ondragend | The source of the drag will receive a dragend event when the drag operation is complete, whether it was successful or not. | ||
| Keyboard | keydown | onkeydown | Fires before keypress, when a key on the keyboard is pressed. | ||
| Keyboard | keypress | onkeypress | Fires after keydown, when a key on the keyboard is pressed. | ||
| Keyboard | keyup | onkeyup | Fires when a key on the keyboard is released | ||
| HTML frame/object | load | onload | Fires when the user agent finishes loading all content within a document, including window, frames, objects and imagesFor elements, it fires when the target element and all of its content has finished loading | ||
| HTML frame/object | unload | onunload | Fires when the user agent removes all content from a window or frame For elements, it fires when the target element or any of its content has been removed | ||
| HTML frame/object | abort | onabort | Fires when an object/image is stopped from loading before completely loaded | ||
| HTML frame/object | error | onerror | Fires when an object/image/frame cannot be loaded properly | ||
| HTML frame/object | resize | onresize | Fires when a document view is resized | ||
| HTML frame/object | scroll | onscroll | Fires when an element or document view is scrolled | , except that a scroll event on document must bubble to the window | |
| HTML form | select | onselect | Fires when a user selects some text in a text field, including input and textarea | ||
| HTML form | change | onchange | Fires when a control loses the input focus and its value has been modified since gaining focus | ||
| HTML form | submit | onsubmit | Fires when a form is submitted | ||
| HTML form | reset | onreset | Fires when a form is reset | ||
| HTML form | focus | onfocus | Fires when an element receives focus either via the pointing device or by tab navigation | ||
| HTML form | blur | onblur | Fires when an element loses focus either via the pointing device or by tabbing navigation | ||
| User interface | focusin | Similar to HTML focus event, but can be applied to any focusable element | |||
| User interface | focusout | Similar to HTML blur event, but can be applied to any focusable element | |||
| User interface | DOMActivate | Similar to XUL command event. Fires when an element is activated, for instance, through a mouse click or a keypress. | |||
| Mutation | DOMSubtreeModified | Fires when the subtree is modified | |||
| Mutation | DOMNodeInserted | Fires when a node has been added as a child of another node | |||
| Mutation | DOMNodeRemoved | Fires when a node has been removed from a DOM-tree | |||
| Mutation | DOMNodeRemovedFromDocument | Fires when a node is being removed from a document | |||
| Mutation | DOMNodeInsertedIntoDocument | Fires when a node is being inserted into a document | |||
| Mutation | DOMAttrModified | Fires when an attribute has been modified | |||
| Mutation | DOMCharacterDataModified | Fires when the character data has been modified | |||
| Progress | loadstart | Progress has begun. | |||
| Progress | progress | In progress. After loadstart has been dispatched. | |||
| Progress | error | Progression failed. After the last progress has been dispatched, or after loadstart has been dispatched if progress has not been dispatched. | |||
| Progress | abort | Progression is terminated. After the last progress has been dispatched, or after loadstart has been dispatched if progress has not been dispatched. | |||
| Progress | load | Progression is successful. After the last progress has been dispatched, or after loadstart has been dispatched if progress has not been dispatched. | |||
| Progress | loadend | Progress has stopped. After one of error, abort, or load has been dispatched. |
Note that the events whose names start with "DOM" are currently not well supported, and for this and other performance reasons are deprecated by the W3C in DOM Level 3. Mozilla and Opera support DOMAttrModified, DOMNodeInserted, DOMNodeRemoved and DOMCharacterDataModified. Chrome and Safari support these events, except for DOMAttrModified.
Touch events
Web browsers running on touch-enabled devices, such as Apple's iOS and Google's Android, generate additional events.| Category | Type | Attribute | Description | Bubbles | Cancelable |
| Touch | touchstart | Fires when a finger is placed on the touch surface/screen. | |||
| Touch | touchend | Fires when a finger is removed from the touch surface/screen. | |||
| Touch | touchmove | Fires when a finger already placed on the screen is moved across the screen. | |||
| Touch | touchenter | Fires when a touch point moves onto the interactive area defined by a DOM element. | |||
| Touch | touchleave | Fires when a touch point moves off the interactive area defined by a DOM element. | |||
| Touch | touchcancel | A user agent must dispatch this event type to indicate when a TouchPoint has been disrupted in an implementation-specific manner, such as by moving outside the bounds of the UA window. A user agent may also dispatch this event type when the user places more touch points on the touch surface than the device or implementation is configured to store, in which case the earliest TouchPoint object in the TouchList should be removed. |
In the W3C draft recommendation, a
TouchEvent delivers a TouchList of Touch locations, the modifier keys that were active, a TouchList of Touch locations within the targeted DOM element, and a TouchList of Touch locations that have changed since the previous TouchEvent.Apple didn't join this working group, and delayed W3C recommendation of its Touch Events Specification by disclosing patents late in the recommendation process.