How can I call the JQuery.on () function when the mouse button is pressed and not when it is released.

JQuery code $(element).on("click", selector, handler)

, the handler function is called after releasing the mouse button from the selected element. Is there a way to trigger an event on mouse click?

+3


source to share


2 answers


You can use a function .mousedown()

to achieve your desired result:

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

      



Or you can use a function .on()

and pass "mousedown" as an action:

$( "#target" ).on('mousedown', function(){});

      

+6


source


you can use .mousedown()



$(document).off("mousedown","#ID").on("mousedown","#ID", function(){
...
});

      

0


source







All Articles