onmousedownEvent
Examples
Execute JavaScript code when the user presses a mouse button:
<p onmousedown="myFunction()">Click the text to change the color.</p>
Try it Yourself »
(More examples at the bottom of this page)
Definition and Usage
The onmousedown event occurs when a mouse button is pressed down.
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 execute 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: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title>.
More Examples
Alert the mouse button that was clicked
Alert the mouse button the user clicked
Alert the element the user clicked
Alert the name of the element the user clicked.
Event Object Other Extensions