jQuery | mousedown() with Examples

The mousedown() method is an inbuilt method in jQuery which works when the left mouse button is pressed down over the selected element.
Syntax:

$(selector).mousedown(function)

Parameters: This function accepts single parameter function which is optional. It is used to specify the function to run when the mousedown event is called.

Return Value: This method returns the selected element with the change.



Below example illustrates the mousedown() method in jQuery:

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>The mousedown Method</title>
        <script src=
        </script>
          
        <!-- jQuery code to show the working of this method -->
        <script>
            $(document).ready(function() {
                $("div").mousedown(function() {
                    alert("Mouse left key was pressed");
                });
            });
        </script>
        <style>
            div {
                width: 200px;
                height: 40px;
                font-weight: bold;
                border: 2px solid green;
                padding: 20px;
            }
        </style>
    </head>
    <body>
        <!-- click on this button and pop up will appear-->
        <div>Welcome to GeeksforGeeks!</div>
    </body>
</html>

chevron_right


Output:
Before click on the paragraph element:

After click on the paragraph element:

Related Articles:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.