onmousedown Event
Definition and usage
An onmousedown event occurs when the user presses the mouse button on an element.
Tip:Event sequence related to onmousedown event (for left mouse button/middle mouse button):
Event sequence related to onmousedown event (for right mouse button):
Example
Execute JavaScript when the mouse button is pressed on the paragraph:
<p onmousedown="myFunction()">Click the text!</p>
More TIY examples are at the bottom of the page.
Syntax
In HTML:
<element onmousedown="myScript">
In JavaScript:
object.onmousedown = function(){myScript};
In JavaScript, use the addEventListener() method:
object.addEventListener("mousedown", myScript);
Note:Internet Explorer 8 and earlier versions do not support addEventListener() method.
Technical details
Bubble: | Supported |
---|---|
Cancelable: | Supported |
Event type: | MouseEvent |
Supported HTML tags: | All HTML elements, except: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style> and <title> |
DOM Version: | Level 2 Events |
Browser support
Event | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
onmousedown | Supported | Supported | Supported | Supported | Supported |
More examples
- Triggers a function with parameters when the button is pressed
- When the mouse button is pressed on the <p> element, change its color to red.
- Remind which mouse button was pressed.
- Remind the user which mouse button was pressed.
- Prompt the element clicked.
- Remind the user of the name of the element clicked.