Sunday, 8 January 2012

HTML DOM Event Object Reference


Event Object

Events are actions that can be detected by JavaScript, and the event object gives information about the event that has occurred.
Sometimes we want to execute a JavaScript when an event occurs, such as when a user clicks a button.
Events are normally used in combination with functions, and the function will not be executed before the event occurs!

Event Attributes

Below is the event attributes that can be inserted into different HTML elements to define event actions.
IE: Internet Explorer, F: Firefox, O: Opera, W3C: W3C Standard.
AttributeThe event occurs when...IEFOW3C
onblurAn element loses focus319Yes
onchangeThe content of a field changes319Yes
onclickMouse clicks an object319Yes
ondblclickMouse double-clicks an object419Yes
onerrorAn error occurs when loading a document or an image419Yes
onfocusAn element gets focus319Yes
onkeydownA keyboard key is pressed31NoYes
onkeypressA keyboard key is pressed or held down319Yes
onkeyupA keyboard key is released319Yes
onloadA page or image is finished loading319Yes
onmousedownA mouse button is pressed419Yes
onmousemoveThe mouse is moved319Yes
onmouseoutThe mouse is moved off an element419Yes
onmouseoverThe mouse is moved over an element319Yes
onmouseupA mouse button is released419Yes
onresizeA window or frame is resized419Yes
onselectText is selected319Yes
onunloadThe user exits the page319Yes

Mouse / Keyboard Attributes

PropertyDescriptionIEFOW3C
altKeyReturns whether or not the "ALT" key was pressed when an event was triggered619Yes
buttonReturns which mouse button was clicked when an event was triggered619Yes
clientXReturns the horizontal coordinate of the mouse pointer when an event was triggered619Yes
clientYReturns the vertical coordinate of the mouse pointer when an event was triggered619Yes
ctrlKeyReturns whether or not the "CTRL" key was pressed when an event was triggered619Yes
metaKeyReturns whether or not the "meta" key was pressed when an event was triggered619Yes
relatedTargetReturns the element related to the element that triggered the eventNo19Yes
screenXReturns the horizontal coordinate of the mouse pointer when an event was triggered619Yes
screenYReturns the vertical coordinate of the mouse pointer when an event was triggered619Yes
shiftKeyReturns whether or not the "SHIFT" key was pressed when an event was triggered619Yes

Other Event Attributes

PropertyDescriptionIEFOW3C
bubblesReturns a Boolean value that indicates whether or not an event is a bubbling eventNo19Yes
cancelableReturns a Boolean value that indicates whether or not an event can have its default action preventedNo19Yes
currentTargetReturns the element whose event listeners triggered the eventNo19Yes
eventPhaseReturns which phase of the event flow is currently being evaluated   Yes
targetReturns the element that triggered the eventNo19Yes
timeStampReturns the time stamp, in milliseconds, from the epoch (system start or event trigger)No19Yes
typeReturns the name of the event619Yes

No comments:

Post a Comment