I want to write to the console is the user is keeping the mouse over an element for more than 2 seconds, this is the code:
var $els = document.querySelectorAll('#myDiv');
for(i = 0; i < $els.length; i++) {
if ($($els[i]).data('track') == 'hover') {
$els[i].addEventListener('mouseover', function (e) {
setTimeout(function() {
if ($($els[i]).is(':hover')) {
console.log('mouse is still over this element');
}
}, 2000);
});
}
}
the message is written to the console after 2 seconds, even if I keep the mouse on the element less than 2 seconds. I am probably missing something in here:
if ($($els[i]).is(':hover')) {
thanks for your help