Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

onmousedown event

onmousedown event

Event Object Reference Event Object

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

  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 be executed 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: , ,
, , ,