Search code examples
javascriptiphonedomcordovadom-events

How to detect a long press on a button/image


I am working on a phonegap project. I need to implement a long press event. How can we detect long press on a image/button using JavaScript?


Solution

  • $('#target').mousedown(function() {
      alert('Handler for .mousedown() called.');
      //start a timer
    });
    
    $('#target').mouseup(function() {
      alert('Handler for .mouseup() called.');
      //stop the timer and decide on long click
    
    });