Tutorialspoint.dev

HTML | onmousedown Attribute

This attribute fires when a mouse button is pressed down on the element. The order of events occur related to the onmousedown event(for the left/mouse button)

  • onmousedown
  • onmouseup
  • onclick

Syntax:

<element onmousedown="script">

Attribute Value: It is supported by all HTML elements. The script event run when onmousedown attribute call.

Example:

<!DOCTYPE html>
<html>
    <head>
        <title>onmousedown attribute</title>
        <style>
            body {
                text-align:center;
            }
            h1 {
                color:green;
            }
        </style>
    </head>
    <body>
        <h1>GeeksforGeeks</h1>
        <h2>onmouseDown A ttribute</h2>
        <p id="sudo" onmousedown="mouseDown()" onmouseup="Geeks()">
        GeeksForGeeks: A computer science portal for Geeks. It is a <br>
        best website for learning computer science.</p>
        <script>
            function Geeks() {
                document.getElementById("sudo").style.color = "green";
            }
            function mouseDown() {
                document.getElementById("sudo").style.color = "red";
            }
        </script>
    </body>
</html>                    

Output:

Supported Browsers: The browser supported by onmousedown attribute are listed below:

  • Apple Safari
  • Google Chrome
  • Firefox
  • Opera
  • Internet Explorer


This article is attributed to GeeksforGeeks.org

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter