How to check mouse holded some sec on a element

javascript, jquery

Solution

I think you are looking for this, here if a `div` gets hover and hold mouse for at least 3 seconds then do your stuff like below

var myTimeout;

$('div').mouseenter(function() {
    myTimeout = setTimeout(function() {
        alert("do your stuff now");
    }, 3000);
}).mouseleave(function() {
    clearTimeout(myTimeout);
});

Problem

How we can check mouse holed some seconds on an element. Means that the function should execute only if the user holds the mouse more than minimum seconds(eg:3 sec) on an element. Many of the answers found in the stack, but that solutions are delaying the execution, but I want to check mouse holed or not, If yes, execute the function else don't make any action. Already asked same question before, but not yet get the answer exactly what I looking Is it possible?

Original source