onmousedown event
Example
Execute JavaScript code when the user presses a mouse button:
<p onmousedown="myFunction()">Click the text to change its color.
p
Try it »
(More examples are available at the bottom of this page)
Definition and Usage
The onmousedown event occurs when a mouse button is pressed.
Tip: The order of events associated with the onmousedown event (left/middle mouse button):
- onmousedown
- onmouseup
- onclick
The order of events associated with the onmousedown event (right mouse button):
- onmousedown
- onmouseup
- oncontextmenu
Syntax
In HTML:
<
element
onmousedown="
SomeJavaScriptCode
">In JavaScript:
object
.onmousedown=function(){
SomeJavaScriptCode
};
| Parameters | Description |
|---|---|
| SomeJavaScriptCode | Required. Specifies the JavaScript to be executed when the event occurs. |
Browser support





All major browsers support the onmousedown event
HTML tags that support the onmousedown event:
The onmousedown attribute applies to all HTMl elements, except:
, , ,
Event Object