The Jquery code
$(element).on("click", selector, handler)
, will trigger the handler function after the mouse button is released from the selected element. Is there a way to trigger the event when the mouse button is pressed?
Asked
Active
Viewed 104 times
3

Ben Carp
- 24,214
- 9
- 60
- 72
-
3try with `.on("mousedown", ...)` – Kaddath May 30 '17 at 09:17
-
1please try, https://api.jquery.com/mousedown/ – manian May 30 '17 at 09:17
-
1[Related](https://stackoverflow.com/questions/19109754/difference-between-mousedown-and-click-in-jquery) – Sandman May 30 '17 at 09:21
2 Answers
6
You can use the .mousedown()
Function to achieve what you want:
$( "#target" ).mousedown(function(){});
Or you can use the .on()
function and pass 'mousedown' as the action:
$( "#target" ).on('mousedown', function(){});

Jan Somers JanS91
- 356
- 3
- 16
0
You can use .mousedown()
$(document).off("mousedown","#ID").on("mousedown","#ID", function(){
...
});

Trimantra Software Solution
- 3,223
- 2
- 25
- 44