jQuery mousedown() Method

You are Here:

jQuery mousedown() Method

The jQuery mousedown() method is used for the following 2 purpose

  1. To run a callback when a specified element is pressed.
  2. To trigger the mousedown event of a specified element.

Run a Callback

In the following example, we will run a callback function when a button is pressed.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <body> <h1>jQuery mousedown() Method</h1> <p>Press Me.</p> <script> $(document).ready(function(){ $("p").mousedown(function(){ alert("Paragraph is pressed."); }); }); </script> </body> </html>

Syntax

$(selector).mousedown(callback);

Parameter Values

ValueTypeExplanation
callbackOptionalSpecifies a function to be called once user mouse is pressed on the element.

Trigger a mousedown Event

In the following example, we will trigger a mousedown event when a button is clicked.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <body> <button>Trigger mousedown Event</button> <script> $(document).ready(function(){ $("p").mousedown(function(){ alert("Paragraph is pressed."); }); $("button").click(function(){ $("p").mousedown(); }); }); </script> </body> </html>

Reminder

Hi Developers, we almost covered 99.5% of jQuery Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in jQuery.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author