Event management is one of the biggest challenges to achieve cross-browser scripting. Every browser has different approaches to handle key strokes.
Prototype Framework handles all cross browser compatibility issues and keeps you free from all trouble related to event management.
Prototype Framework provides Event namespace, which is replete with methods, that all take the current event object as an argument, and happily produce the information you're requesting, across all major browsers.
Event namespace also provides a standardized list of key codes you can use with keyboard-related events. The following constants are defined in the namespace −
|S.No.||Key Constant & Description|
Represent back space key.
Represent tab key.
Represent return key.
Represent esc key.
Represent left key.
Represent up key.
Represent right key.
Represent down key.
Represent delete key.
Represent home key.
Represent end key.
Represent page up key.
Represent page down key.
Before we start, let us see an example of using an event method. This example shows how to capture the DOM element on which the event occurred.
Here is a complete list of all the methods related to Event. The functions you're most likely to use a lot are observe, element and stop.
NOTE − Make sure you at least have the version 1.6 of prototype.js.
|S.No.||Method & Description|
Returns the DOM element on which the event occurred.
Extends the event with all of the methods contained in Event.Methods.
Returns the first DOM element with a given tag name, upwards from the one on which the event occurred.
Determines whether a button-related mouse event was about the "left" (primary, actually) button.
Registers an event handler on a DOM element.
Returns the absolute horizontal position for a mouse event.
Returns the absolute vertical position for a mouse event.
Stops the event's propagation and prevents its default action from being triggered eventually.
Unregisters an event handler.
Unregisters all event handlers registered through observe. Automatically wired for you. Not available since 1.6.