Home >>jQuery Tutorial >jQuery mousedown() Method

jQuery mousedown() Method

jQuery mousedown() Method

jQuery mousedown() method in jQuery is used to attaches a function or triggers the mousedown event to run when a mousedown event occurs.

Syntax:
Trigger the mousedown event for the selected elements: $(selector).mousedown()
Attach a function to the mousedown event: $(selector).mousedown(function)

Parameter Values

Parameter Description
function It is optional parameter and used to specifies the function to run when the mousedown event is triggered
Here is an Example of jQuery mousedown() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".box").mouseup(function(){
$(this).after("<p style='color:orange;'>Released Mouse button .</p>");
});
$(".box").mousedown(function(){
$(this).after("<p style='color:green;'>Pressed down mouse button.</p>");
});
});
</script>
</head>
<body>
<div class="box">click on me and release the mouse button over this element</div>
</body>
</html>

Output:
click on me and release the mouse button over this element

No Sidebar ads