mousedown() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:mousedown

Description

The mousedown() method triggers the mousedown event, or sets function as mousedown event handler.

Syntax

$(selector).mousedown(function);
Parameter Require Description
function Optional. function to run when the mousedown event is triggered

The following code shows how to Press down the left mouse button over a <div> element to insert some text:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("div").mouseup(function(){
        $(this).after("<p style='color:green;'>Mouse button released.</p>");
    });/*w w  w . j  a  va2s  .c  o  m*/
    $("div").mousedown(function(){
        $(this).after("<p style='color:purple;'>Mouse button pressed down.</p>");
    });
});
</script>
</head>
<body>

<div>Press down and release the mouse button over this div element.</div>

</body>
</html>

Related Tutorials