.mousedown()
methodThe .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.
.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. |
.mousedown()
method ExampleTrigger 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(); }
.mousedown([eventData,]handler)
method ExampleFollowing is a simple example that how texts when mousedown event triggering.
$("p").mousedown( function () { $(this).hide(); });