![]() |
Definition and UsageThe 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):
The order of events related to the onmousedown event (for the right mouse button):
Applies toThe onmousedown attribute is part of the Event Attributes, and can be used on any HTML elements.
Browser Support
|
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>
html onmousedown attribute |
How to Execute a JavaScript when pressing a mouse button over a paragraph - HTML onmousedown Attribute | HTML Attribute |
Read Full: | HTML Attribute |
Type: | Develop |
Category: | Web Tutorial |
Sub Category: | HTML Attribute |
Uploaded: | 1 week ago |
Uploaded by: | Admin |
Views: | 54 |
Reffered: https://www.w3schools.com/tags/att_onmousedown.asp