Introduction:

In this article we will explain how to use mousedown() method in jquery or  how to attach mouse down event to a html element.

Description:

 jQuery mousedown() method adds an event handler function to an HTML element. This function is executed, when the left mouse button is pressed down, at the time while the mouse is over the HTML element.

syntax:

$(selector).mousedown(function)

jQuery mousedown() example

Let's take an example to see the mousedown() event in jQuery. In this example, when you left mouse button is pressed down on “h1” tag then “mouse down event triggered” text shown in “h2” tag.

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Jquery Tutorials</title>
    <script src="Scripts/jquery-1.8.2.min.js"></script>
    <script>       
            $(document).ready(function () {
                $("#h1").mousedown(function(){   
                    $("h2").text("mouse down event triggered");
                });
            });
    </script>  
</head>
<body>
    <h1 id="h1">Click here your Left mouse button.</h1>
    <h2></h2>       
</body>
</html>

Output:


I hope it will help to you after reading it.

0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

Welcome to SQL Tutorials Point

Don't have an account? Click here to Create a new account, it takes less than a minute.