event object
Represents the state of an event, such as the element in which the event occurred, the state of the keyboard keys, the location of the mouse, and the state of the mouse buttons.
![]() |
Members
The event object has these types of members:
Properties
The event object has these properties.
| Property | Description |
|---|---|
|
Gets the URL of a Jump List item that is removed. This property is not supported for Windows Store apps using JavaScript. | |
|
Gets a value that indicates whether the Alt key is pressed. | |
|
Retrieves a value that indicates the state of the ALT key. For the standards based property, see altKey. | |
|
Retrieves a value that indicates the state of the left ALT key. | |
|
Sets or retrieves the mouse button pressed by the user. This property is not supported for Windows Store apps using JavaScript. For the standards based property that can be used with Windows Store apps using JavaScript , see button. | |
|
Gets the Thumbnail Toolbar button ID that is clicked. This property is not supported for Windows Store apps using JavaScript. | |
|
Sets or retrieves whether the current event should bubble up the hierarchy of event handlers. | |
|
Sets or retrieves the x-coordinate of the mouse pointer, or user's finger, position relative to the client area of the window, excluding window decorations and scroll bars. For the standards based property, see clientX. | |
|
Sets or retrieves the y-coordinate of the mouse pointer, or user's finger, position relative to the client area of the window, excluding window decorations and scroll bars. | |
|
Returns a reference to the constructor of an object. | |
|
Retrieves a value that indicates whether the document contains additional content after processing the current LayoutRect object. | |
|
Gets a value that indicates whether the Ctrl key is pressed. | |
|
Sets or retrieves the state of the CTRL key. For the standards based property, see ctrlKey. | |
|
Sets or retrieves the state of the left CTRL key. | |
|
Sets or retrieves the body of the onmessage request. | |
|
Sets or retrieves the data column affected by the oncellchange event. | |
|
Sets or retrieves the object from which activation or the mouse pointer is exiting during the event. | |
|
Sets or retrieves the Unicode key code associated with the key that caused the event. | |
|
Retrieves the position of the next page within a print template. | |
|
Sets or retrieves the x-coordinate of a pointer's position relative to the object firing the event. | |
|
Sets or retrieves the y-coordinate of a pointer's position relative to the object firing the event. | |
|
Sets or retrieves the scheme, hostname, and port of the document that fired the onmessage event. | |
|
Sets or retrieves the name of the property that changes on the object. | |
|
Sets or retrieves the result of the data transfer for a data source object. | |
|
Sets or retrieves from a data source object a reference to the default record set. | |
|
Retrieves whether the onkeydown event is being repeated. For the standards based property, see repeat. | |
|
Sets or retrieves the return value from the event. | |
|
Retrieves the clipboard type when oncontentsave fires. | |
|
Sets or retrieves the x-coordinate of the mouse pointer's position relative to the user's screen. For the standards based property, see screenX. | |
|
Sets or retrieves the y-coordinate of the mouse pointer's position relative to the user's screen. For the standards based property, see screenY. | |
|
Retrieves the state of the SHIFT key. For the standards based property, see shiftKey. | |
|
Retrieves the state of the left SHIFT key. | |
|
Sets or retrieves the object that fired the event. | |
|
Sets or retrieves the filter object that caused the onfilterchange event to fire. | |
|
Retrieves the URN of the behavior that fired the event. | |
|
Sets or retrieves a reference to the object toward which the user is moving the mouse pointer or, for a touch device, a finger. | |
|
Sets or retrieves the event name from the event object. | |
|
Sets or retrieves the fully qualified URL of the document that fired the event. | |
|
Retrieves the distance and direction the wheel button has rolled. | |
|
Sets or retrieves the x-coordinate (in pixels) of the mouse pointer, or user's finger, offset from the closest relatively positioned parent element of the element that fired the event. | |
|
Sets or retrieves the y-coordinate (in pixels) of the mouse pointer, or user's finger, offset from the closest relatively positioned parent element of the element that fired the event. |
Standards information
- Document Object Model (DOM) Level 2 HTML Specification, Section 1.6.5
Remarks
The event object is available only during an event—that is, you can use it in event handlers but not in other code.
Although all event properties are available to all event objects, some properties might not have meaningful values during some events. For example, the fromElement and toElement properties are meaningful only when processing the onmouseover and onmouseout events.
In Microsoft Visual Basic Scripting Edition (VBScript), you must access the event object through the window object.
Several of the properties that apply to this object are not writable unless this object has been created using the createEventObject method. The following is a list of these properties: altKey, altLeft, button, clientX, clientY, ctrlKey, ctrlLeft, dataFld, offsetX, offsetY, propertyName, qualifier, reason, repeat, screenX, screenY, shiftKey, shiftLeft, srcUrn, type, x, and y.
Examples
This example uses the event object to check whether the user clicked the mouse within a link, and to prevent the link from being navigated if the SHIFT key is down. It also display mouse position within the <body> element:
<!DOCTYPE html> <html> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <title>Cancels Links</title> <style> body { border: 1px black solid; width: 32em; padding: 0 1em; } </style> </head> <body id="bodyTag"> <p>Mouse over this black box (i.e., the <body> element) to see mouse position. <p>And click <a href="http://www.bing.com" target="_blank">this</a> link with and without holding the SHIFT key down.</p> <p id="mousePositionDisplay">Mouse position:</p> <script> var bodyElement = document.getElementById('bodyTag'); bodyElement.addEventListener('click', cancelLink, 'false'); bodyElement.addEventListener('mousemove', reportMousePosition, 'false'); function cancelLink() { if (window.event.srcElement.tagName == "A" && window.event.shiftKey) { window.event.returnValue = false; } } function reportMousePosition() { document.getElementById('mousePositionDisplay').innerHTML = "Mouse position: (" + window.event.x + ", " + window.event.y + ")"; } </script> </body> </html>
