JSFiddle - React, Tailwind, and code Playground
HTML
<div id="foo">Click and hold for two seconds...</div>
CSS
#foo {
width:100px;
padding:1em;
color:white;
background:red;
font-weight:bold;
text-align:center;
font-family:sans-serif;
vertical-align:middle;
border:2px solid black;
}
JavaScript
(function() {
var foo=$('#foo'), tf=null;
foo.mousedown(function() {
tf = setTimeout(function() {
alert('Two Seconds!');
}, 2000);
});
foo.mouseup(function() {
clearTimeout(tf);
});
})();