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 Table
The following table lists the members exposed by the
event
object.
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.
<HTML>
<HEAD><TITLE>Cancels Links</TITLE>
<SCRIPT LANGUAGE="JScript">
function cancelLink() {
if (window.event.srcElement.tagName == "A" && window.event.shiftKey)
window.event.returnValue = false;
}
</SCRIPT>
<BODY >
This example displays the current mouse position in the browser's status window.
Standards Information
This object is defined in
World Wide Web Consortium (W3C) Document Object Model (DOM) Level 2
.
Applies To