Mouseover / mouseout event fix: isMouseLeaveOrEnter


/ Published in: JavaScript
Save to your folder(s)

Usage: onmouseout='if (isMouseLeaveOrEnter(event, this)) YourActionHere();' onmouseover='if (isMouseLeaveOrEnter(event, this)) YourOtherActionHere();'


Copy this code and paste it in your HTML
  1. // from http://www.dynamic-tools.net/toolbox/isMouseLeaveOrEnter/
  2. // this function determines whether the event is the equivalent of the microsoft
  3. // mouseleave or mouseenter events.
  4. function isMouseLeaveOrEnter(e, handler)
  5. {
  6. if (e.type != 'mouseout' && e.type != 'mouseover') return false;
  7. var reltg = e.relatedTarget ? e.relatedTarget :
  8. e.type == 'mouseout' ? e.toElement : e.fromElement;
  9. while (reltg && reltg != handler) reltg = reltg.parentNode;
  10. return (reltg != handler);
  11. }

URL: http://www.dynamic-tools.net/toolbox/isMouseLeaveOrEnter/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.