English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag Directory

HTML onmousedown Event Attribute

The onmousedown attribute is used to get or set the event handler function for the mousedown event of the current element

HTML Event Attributes

Online Example

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

<!DOCTYPE html>
<html>
<head>
<title>Use of HTML onmousedown Event Attribute (Basic Tutorial Website oldtoolbag.com)</title>
</head>
<body>
<p id="p1" onmousedown="mouseDown()" onmouseup="mouseUp()">
Click the text! When the mouse button is pressed on this paragraph, the mouseDown() function will be triggered. This function sets the text color to red. When the mouse button is released, the mouseUp() function will be triggered. The mouseUp() function sets the text color to green.</p>
<script>
function mouseDown() {
  document.getElementById("p1").style.color = "red";
}
function mouseUp() {
  document.getElementById("p1").style.color = "green";
}
</script>
</body>
</html>
Test and see ‹/›

The mousedown event is triggered at the moment the mouse button is pressed on the current element

Browser Compatibility

IEFirefoxOperaChromeSafari

All major browsers support the onmousedown event attribute

Definition and Usage

The onmousedown attribute is triggered when a mouse button is pressed on an element.

Tip: and onmousedown event triggering order (left/(middle mouse button):

  • onmousedown

  • onmouseup

  • onclick and onmousedown event triggering order (right mouse button):

  • onmousedown

  • onmouseup

  • oncontextmenu

Note: The onmousedown attribute cannot be used with the following elements: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, or <title>.

HTML 4.01 and HTML5Differences between

None.

Syntax

<element onmousedown="script">

Attribute Value

ValueDescription
scriptSpecifies the script to be executed when the onmousedown event is triggered.


HTML Event Attributes