Javascript Ajax jQuery Html PHP Example Quiz New MORE

How to add mousedown() event jQuery

The mousedown() method is an inbuilt method in jQuery. It works when left mouse button is pressed down and released over a HTML element. his method can accept only one parameter and this is optional.

Syntax:

$(selector).mousedown(parameter)

Example:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>mouseup demo</title>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>

<p>Press mouse and release here.</p>

<script>
$( "p" ).mouseup(function() {
    $( this ).append( "<span style='color:#f00;'>Mouse up.</span>" );
  })
  $( "p" ).mousedown(function() {
    $( this ).append( "<span style='color:#00f;'>Mouse down.</span>" );
  });
</script>

</body>
</html>

Run it Yourself »