You could setup special mouse events using Javascript that fires when the pointer is enter or hovering over a specific HTML element (i.e: object.addEventListener("mouseover", theScript); ). But how does it work?

Is it like a classic collison detection? When the mouse pointer X and Y coordinates is inside the boundaries of the element it reports to all listeners of the event.

This is maybe something that is browser specific but I guess there is similiar approaches between the browsers(?).

1 Answer 1



The browser has to know where to put all the elements it draws, so when the OS tells it that the mouse has moved, it can do simple left < X < right and top < Y < bottom checks with the from position and the to position to see if the mouse has entered (or exited) the element. It can then deal with all the :hover, mouseover, etc.

The OS will do a similar thing with the actual hardware messages and open windows.

The exact code will of course vary between browsers and OSs, but the basic algorithm is very simple.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.