Horje
HTML onmousedown Event Attribute
The onmousedown attribute in HTML is an event attribute that triggers a script when a mouse button is pressed down on an element. This event is part of the broader category of mouse events in the HTML DOM (Document Object Model).
 

Example of HTML onmousedown Event Attribute

It will Execute a JavaScript when pressing a mouse button over a paragraph.
index.html
Example: HTML

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

Output should be:

Example of HTML onmousedown Event Attribute

Definition and Usage of HTML onmousedown Event Attribute

The onmousedown attribute fires when a mouse button is pressed down on the element.

Tip: The order of events related to the onmousedown event (for the left/middle mouse button):

  1. onmousedown
  2. onmouseup
  3. onclick

The order of events related to the onmousedown event (for the right mouse button):

  1. onmousedown
  2. onmouseup
  3. oncontextmenu

Browser Support of HTML onmousedown Event Attribute

Browser Support of HTML onmousedown Event Attribute

Syntax of HTML onmousedown Event Attribute

< element onmousedown=" script ">

Attribute Values of HTML onmousedown Event Attribute

Value Description
script The script to be run on onmousedown

Technical Details of HTML onmousedown Event Attribute

Supported HTML tags: All HTML elements, EXCEPT: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title>

How to Execute a JavaScript when pressing a mouse button over a paragraph

Click the text! The mouseDown() function is triggered when the mouse button is pressed down over this paragraph. The function sets the color of the text to red. The mouseUp() function is triggered when the mouse button is released. The mouseUp() function sets the color of the text to green.

index.html
Example: HTML

<!DOCTYPE html>
<html>
<body>
<p id="p1" onmousedown="mouseDown()" onmouseup="mouseUp()">
Click the text! The mouseDown() function is triggered when the mouse button is pressed down over this paragraph. The function sets the color of the text to red. The mouseUp() function is triggered when the mouse button is released. The mouseUp() function sets the color of the text to green.
</p>
<script>
function mouseDown() { document.getElementById("p1").style.color = "red";
}
function mouseUp() { document.getElementById("p1").style.color = "green";
}
</script>
</body>
</html>

Output should be:

How to Execute a JavaScript when pressing a mouse button over a paragraph




html event attributes

Related Articles
List of Mouse Events Attribute HTML Mouse Events Attribute
HTML onclick Event Attribute HTML Mouse Events Attribute
HTML ondblclick Event Attribute HTML Mouse Events Attribute
HTML onmousedown Event Attribute HTML Mouse Events Attribute
HTML onmousemove Event Attribute HTML Mouse Events Attribute
HTML onmouseout Event Attribute HTML Mouse Events Attribute
HTML onmouseover Event Attribute HTML Mouse Events Attribute
HTML onmouseup Event Attribute HTML Mouse Events Attribute
HTML onwheel Event Attribute HTML Mouse Events Attribute

Single Articles
Example of HTML onmousedown Event Attribute HTML Mouse Events Attribute
Definition and Usage of HTML onmousedown Event Attribute HTML Mouse Events Attribute
Browser Support of HTML onmousedown Event Attribute HTML Mouse Events Attribute
Syntax of HTML onmousedown Event Attribute HTML Mouse Events Attribute
Attribute Values of HTML onmousedown Event Attribute HTML Mouse Events Attribute
Technical Details of HTML onmousedown Event Attribute HTML Mouse Events Attribute
How to Execute a JavaScript when pressing a mouse button over a paragraph HTML Mouse Events Attribute

Type :
Develop
Category :
Web Tutorial
Sub Category :
HTML Mouse Events Attribute
Uploaded by :
Admin


Read Article
https://horje.com/learn/1434/reference