Click and Hold event listener with JQuery

by in , on

I have did some experiment with click event. I need to hold the click for a specific amount of time and when user release the mouse that time my defined event will trigger with it. And i have achieved that and now want to share it with you. I have also implemented the touchstart and touchend event into it and tested in chrome and its working perfect. So this is simple demo for click and hold event listener.

I have used setInterval() and clearInterval() for time delay. First we have to use mousedown event, and for release event we call to mouseup or mouseleave or both event with the same element. I have bind these event with .on() event handler.  Here is the demo of the above code:

Click and Hold Event Demo

See the Pen Click and Hold event listener with JQuery by Jogesh Sharma (@webomnizz) on CodePen.