jQuery Tutorial Tutorials - jQuery .mousedown() method

jQuery .mousedown() method

The .mousedown() method in jQuery is used to bind an event handler to the mousedown event on the elements, or trigger that event on an element.

When the mouse pointer is over the element and any mouse button is pressed, the event mousedown is fired.

jQuery .mousedown() method Syntax

.mousedown()
.mousedown(handler)
.mousedown(eventData,handler)

.mousedown(handler) and .mousedown(eventData,handler) are shortcut for .on( "mousedown", handler )

.mousedown() is shortcut for .trigger( "mousedown" )

Parameter Type Description
handler Function A function to execute when the mousedown is triggered on the matched element.
eventData Anything Additional data passed to the event handler.

jQuery .mousedown() method Example

example

Trigger the mousedown event on target:
HTML

<div id="target">target</div>
<div id="btn">
  Trigger mousedown event on target
</div>

jQuery

$( "#target" ).mousedown(function() {
    console.log( "mousedown." );
});

$("#btn").click(function(){
    $( "#target" ).mousedown();
}

jQuery .mousedown([eventData,]handler) method Example

example

Following is a simple example that how texts when mousedown event triggering.

$("p").mousedown( function () { $(this).hide(); });

Try now

Date:2019-08-30 01:00:42 From:www.Lautturi.com author:Lautturi