Why can’t I reliably capture a mouseout event?

I know that you don’t want a workaround, but you don’t need to check mouse’s x/y to know if you are in or out an element. You could simply check the element from which the mousemove event was fired. If you put a mousemove on document, the event will fire from one of its children, and you can compare that element with your element to know if it is one of its descendants.

Or you could go up the parentNode tree and stop if you find your element. Then you know you are inside the element and still in it, otherwise you reach the document and you are out.

Some browsers implement the mouseenter/mouseleave events that, I’ve noticed, are more accurate than mouseout. Prototype and jQuery have a workaround for browsers that don’t implement these new events. Mouseleave does not fire from an element’s children, whereas mouseout does.

Leave a Comment