onmousedownEvent

事件对象参考手册Event Object

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

  1. onmousedown
  2. onmouseup
  3. onclick

The order of events associated with the onmousedown event (right mouse button):

  1. onmousedown
  2. onmouseup
  3. 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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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