Fires when the user clicks the object with either mouse button.
Inline |
<element onmousedown = "handler" ... > |
Script |
object.onmousedown = handler |
Bubbles |
Yes |
Cancels |
Yes |
To invoke |
Click a mouse button. |
Default action |
Initiates actions associated with the event and with the object being clicked. |
A mousedown event occurs when the pointing device button is pressed over an element. The button property can be used to determine which mouse button is pressed.
This event is valid for most elements.
While event handlers in the Document Object Model do not receive parameters directly, the handler can query the event object for data.
Event Object Properties
altKey |
Retrieves the current state of the ALT key. |
button |
Retrieves which mouse button, if any, is pressed. |
cancelBubble |
Sets or retrieves whether the current event should bubble up the hierarchy of event handlers. |
clientX |
Retrieves the x-coordinate of the position of the cursor when the mouse is clicked, relative to the size of the client area of the window but excluding window decorations or scroll bars. |
clientY |
Returns the y-coordinate of the position of the cursor when the mouse is clicked, relative to the size of the client area of the window but excluding window decorations or scroll bars. |
ctrlKey |
Retrieves the state of the CTRL key. |
offsetX |
Retrieves the horizontal coordinate of the mouse's position relative to the object firing the event. |
offsetY |
Retrieves the vertical coordinate of the mouse's position relative to the object firing the event. |
returnValue |
Sets or retrieves the return value from the event. |
screenX |
Retrieves the horizontal position of the mouse, in pixels, relative to the user's screen. |
screenY |
Retrieves the vertical position of the mouse, in pixels, relative to the user's screen. |
shiftKey |
Retrieves the state of the SHIFT key. |
srcElement |
Retrieves the object that fired the event. |
type |
Retrieves the event name from the event object. |
x |
Returns the horizontal position of the mouse when the event fires. |
y |
Returns the vertical position of the mouse when the event fires. |
This example shows how the origin of the onmousedown event is determined when event bubbling is used.
Sample Code
<body onmousedown="alert(event.srcElement.tagName)">
Show me
onmousemove, onmouseout, onmouseover, onmouseup