title: How to check if mouse is still over element in Javascript
body: <p>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:</p>
  
  <pre><code>var $els = document.querySelectorAll('#myDiv');
      for(i = 0; i &lt; $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);
              });
          }
      }
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>if ($($els[i]).is(':hover')) {
  </code></pre>
  
  <p>thanks for your help</p>