How to use JQuery Event mousedown() Method

This article describe about jQuery Event mousedown() Method.
  • 2475

jQuery Event mousedown() Method

When mouse pointer  is over an element, and mouse button is pressed down then mousedown event occur.

The mousedown event require the button to be pressed down, not released unlike the click event.

And mousedown() method triggers the mousedown event.

Example

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

    $(document).ready(function () {

        $("button").mousedown(function () {

            $("p").slideToggle();

        });

    });

</script>

</head>

<body>

<p>This is my paragraph.</p>

<button>Toggle</button>

</body>

</html>

 

Output

 

mousedowm method pic45.jpg

 

Note: In the above declared output when mouse pressed hide the paragraph.


Trigger the mousedown Event

Generate the  Trigger for mousedown event of selected element.

 

Example

 

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

    $(document).ready(function () {

        $("button").mousedown(function () {

            $("div").slideToggle();

        });

        $("#mousePara").mouseover(function () {

            $("button").mousedown();

        });

    });

</script>

</head>

<body>

<div>

<p>This is a first paragraph.</p>

<p>This is  second paragraph.</p>

</div>

<button>Toggle</button>

<p id="mousePara"> Wnen you mouse over this paragraph, then activate the mousedown event for the button.</p>

</body>

</html>

 

Output

 

mousedown mehtod pic46.jpg

 

Bind a Function to the mousedown Event

It is define a function to run when mousedown event generate the trigger for the selected element.

 

Syntax

 

$(selector).mousedown(function)

 

You may also want to read these related articles Click here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.