JavaScript: test if a div is hovered

Solved
Hi everyone, so I have a div
 <div id="madiv">#contenu</div> 

and I’d like to know how a JavaScript function with a setInterval
 window.setInterval("mafonction()", 1); function mafonction() { if ( /* if madiv is hovered */ ){ /* XXX */ } } 

could check if madiv is hovered by the cursor.
Thanks in advance for your answer.

Signature removed by moderation.

2 answers

  1. Hello,
    You can get something by using onmouseover/mouseenter with an event handler/listener, see here

    https://developer.mozilla.org/en-US/docs/Web/Events/mouseover
    or you use the function fallback or directly the event object (compare its value)

    Or a cheating trick using the mouse coordinates to detect if it is in the right area.
    1. The thing with onmouseover events is that it only controls entry and exit... that's not what I want.