DOM2 Events - Usage

DOM2Event objects contain the following properties and methods on event objects. A more complete description of the individual properties and methods can be found in a DOM reference. Elements that are not part of the DOM2 Events standard are noted.

event.altKey

For a mouse event, a Boolean that indicates if the Alt key was depressed during the event.

event.bubbles

A Boolean that indicates if the event can bubble.

event.button

For click, double-click, mouseup and mousedown events, an indicator of what button was clicked.

event.cancelable

A Boolean that indicates if the event has a default action associated which can be canceled (with event.preventDefault()).

event.clientX

For a mouse event, the distance between the left side of the client area and the event.

event.clientY

For a mouse event, the distance between the top of the client area and the event.

event.ctrlKey

For a mouse event, a Boolean that indicates if the Ctrl key was depressed during the event.

event.currentTarget

A reference to the element to which the current event listener is attached (and, in IE, to which the event has bubbled).

event.detail

For click and double-click events, the number of mouse button clicks.

event.eventPhase

An integer indicating the current phase of the event propagation. Equal to either Event.AT_TARGET or Event.BUBBLING_PHASE.

event.keyCode

For keyboard (keydown and keyup) events, the Unicode value of the character that corresponds to what key was pressed.

event.pageX

For a mouse event, the distance between the left side of the document and the event. NON-STANDARD

event.pageY

For a mouse event, the distance between the top of the document and the event. NON-STANDARD

event.relatedTarget

For mouseover and mouseout events, a reference to the other element involved in the event (for a mouseover, it's the object being left by the mouse; for a mouseout, it's the object being entered by the mouse).

event.screenX

For a mouse event, the distance between the left side of the screen and the event.

event.screenY

For a mouse event, the distance between the top of the screen and the event.

event.shiftKey

For a mouse event, a Boolean that indicates if the Shift key was depressed during the event.

event.target

A reference to the element upon which the event occured.

event.timeStamp

A Date object that specifies when the event happened.

event.type

A string indicating the type of the triggering event.

event.view

A reference to the window in which the event occured.

preventDefault()

Synopsis

event.preventDefault()

Returns

Nothing.

Description

For events that have a default action associated with them (ie, clicking on a link loads the linked document), preventDefault() prevents this default action from occuring. It is similar to adding return false at the end of a traditional event handler but with the exception that his method can be called at anytime in an event handler and not just at the end.

stopPropagation()

Synopsis

event.stopPropagation()

Returns

Nothing.

Description

stopPropagation() stops the bubbling of an event through the document hierarchy. In true DOM2 Event compliant browsers (Mozilla and NS6+), it can also be used during the capture phase of event propagation to prevent further propagation (so the at_target and bubbling phases don't even occur).

dom2_events.js also defines the following function that must be used to make IE events DOM2 compliant (see the install instructions and the example for further information on usage of this function):

initRegistration()

Synopsis

DOM2Event.initRegistration(element)

Arguments

element

An optional reference to an element in the document.

Returns

Nothing.

Description

initRegistration() allows you to use the DOM2 addEventListener() and removeEventListener() methods to register and de-register event listeners (see a good DOM reference on the usage of these methods). If the function is passed a element reference argument, then the DOM2 methods are added to just that element. If no argument is passed to the function, then the DOM2 methods are added to every element in the document including the document object.

More about this script

Related to this script

Licensing

This script is released under a Creative Commons License.