Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM Event Object

HTML DOM Events


HTML DOM Events

HTML DOM events allow JavaScript to register different event handlers on HTML document elements.

Events are usually combined with functions, and a function is not executed until the event occurs (such as a user clicking a button).

Tip: The event model was standardized in W3C Level 2 DOM Events.


HTML DOM Events

DOM: Indicates the DOM attribute level used.

Mouse Events

property Description DOM
onclick An event handler called when the user clicks an object. 2
oncontextmenu Triggered when the user right-clicks the mouse to open the context menu.  
ondblclick An event handler called when the user double-clicks an object. 2
onmousedown A mouse button is pressed. 2
onmouseenter Triggered when the mouse pointer moves over an element. 2
onmouseleave Triggered when the mouse pointer moves out of an element. 2
onmousemove The mouse is moved. 2
onmouseover The mouse is moved over an element. 2
onmouseout The mouse is moved away from an element. 2
onmouseup A mouse button is released. 2

Keyboard Events

property Description DOM
onkeydown A keyboard key is pressed. 2
onkeypress A keyboard key is pressed and released. 2
onkeyup A keyboard key is released. 2

Frame/Object Events

property Description DOM
onabort Image loading is interrupted. ( ) 2
onbeforeunload This event is triggered when the page is about to be left (refreshed or closed). 2
onerror An error occurs while loading a document or image. ( , and )  
onhashchange This event is triggered when the anchor part of the current URL is changed.  
onload A page or an image finishes loading. 2
onpageshow This event is triggered when a user visits a page.
onpagehide This event is triggered when a user leaves the current page to navigate to another page.
onresize A window or frame is resized. 2
onscroll An event that occurs when the document is scrolled. 2
onunload The user exits the page. ( and ) 2

Form Events

property Description DOM
onblur Triggered when an element loses focus. 2
onchange This event is triggered when the content of a form element changes ( , ,
clientY Returns the vertical coordinate of the mouse pointer when the event is triggered. 2
ctrlKey Returns whether the "CTRL" key was pressed when the event was triggered. 2
Location Returns the location of the key on the device. 3
charCode Returns the letter code of the key value triggered by the onkeypress event. 2
key Returns the identifier of a key when it is pressed. 3
keyCode Returns the character code of the key value triggered by the onkeypress event, or the key code of the onkeydown or onkeyup event. 2
which Returns the character code of the key value triggered by the onkeypress event, or the key code of the onkeydown or onkeyup event. 2
metaKey Returns whether the "meta" key was pressed when the event was triggered. 2
relatedTarget Returns the node related to the event's target node. 2
screenX Returns the horizontal coordinate of the mouse pointer when an event is triggered. 2
screenY Returns the vertical coordinate of the mouse pointer when an event is triggered. 2
shiftKey Returns whether the "SHIFT" key was pressed when the event was triggered. 2

Method

Method Description W3C
initMouseEvent() Initializes the values of a mouse event object. 2
initKeyboardEvent() Initializes the values of a keyboard event object. 3