JSFiddle - React, Tailwind, and code Playground
HTML
<button id="target">Hold for three seconds</button>
JavaScript
$( "#target" ).on({
mousedown: function() {
$(this).data('timer', setTimeout(function() {
foo();
}, 3000));
},
mouseup: function() {
clearTimeout( $(this).data('timer') );
}
});
function foo() {
alert('Yaay !')
}