HTML onmousedown Event Attribute

Description

The event attribute onmousedown allows you to set the script to fire when you click on an element.

Syntax

<element onmousedown="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE html> 
  <html> 
    <head>
      <title>onmousedown and onmouseup event</title> 
      <style> 
        div {
        width: 100px;
        height: 50px;
        border: 1px solid black;
        color: black;
        text-align: center;
      }
      </style> 
    </head> 
    <body> 
    <p>Click on an element to demonstrate the script:</p> 
    <div id="code" onmousedown="mouseDown()" onmouseup="mouseUp()">&spades; &clubs; &hearts; &diams;<br>&diams; &hearts; &clubs; &spades; 
    </div> 
<script> 
function mouseDown() {
  document.getElementById("code").style.backgroundColor="orange";  
} 
function mouseUp() {
  document.getElementById("code").style.backgroundColor="purple";  
} 
</script> 
  </body> 
</html>

Supported Tags

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

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
YesYesYesYesYesYes
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
YesYesYesYesYesYes