HTML onmousedown Attribute: The HTML onmousedown attribute is defined as it fires when a mouse button is pressed down on the element. It is supported by all HTML elements. The script event runs when onmousedown attribute call. And the order of events occur related to the onmousedown event(for the left/mouse button)
- onmousedown
- onmouseup
- onclick
HTML onmousedown Attribute
This attribute can be applied to all the HTML elements.
Syntax: <element onmousedown=”script”>
Browser Support
This attribute is supported by the following browsers:
- Chrome
- Safari
- Opera
- Internet Explorer
- Firefox
Example: for <p> element
<!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: