Ανάπεμπση onmousedown

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):

  1. onmousedown
  2. onmouseup
  3. onclick

Event sequence related to onmousedown event (for right mouse button):

  1. onmousedown
  2. onmouseup
  3. oncontextmenu

Example

Execute JavaScript when the mouse button is pressed on the paragraph:

<p onmousedown="myFunction()">Click the text!</p>

Try it yourself

More TIY examples are available at the bottom of the page.

Syntax

In HTML:

<element onmousedown="myScript">

Try it yourself

In JavaScript:

object.onmousedown = function(){myScript};

Try it yourself

In JavaScript, use the addEventListener() method:

object.addEventListener("mousedown", myScript);

Try it yourself

Note:Internet Explorer 8 or earlier versions do not support addEventListener() method.

Technical details

Bubbling: Supported
Cancellable: 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.
Ανακάλυψη του κουμπιού του ποντικιού που πατήθηκε.
Ανακάλυψη του κουμπιού του ποντικιού που πατήθηκε από τον χρήστη.
Εμφάνιση του στοιχείου που κλικάρετε.
Ανακάλυψη του ονόματος του στοιχείου που κλικάρετε από τον χρήστη.