make your mouse out event works right


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

mouse out event of a div will be triggered even mouse entered a element with in a div which we do not want it happen.
But all browsers are agree on it...


Copy this code and paste it in your HTML
  1. var show = function (divId){
  2. var div = $j('#'+divId);
  3. div.show();
  4. div.focus();
  5. div.bind("mouseout",function(e){
  6. if (!e) var e = window.event;
  7. var tg = (window.event) ? e.srcElement : e.target;
  8. if (tg.nodeName != 'DIV') return;
  9. var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
  10. while (reltg != tg && reltg.nodeName != 'BODY')
  11. reltg= reltg.parentNode
  12. if (reltg== tg) return;
  13. $j(this).hide();
  14. });
  15. };
  16.  
  17.  
  18. /***sample***/
  19. html:
  20. <div onmouseout="alert('oh no!! mouse left me alone...');">
  21. <a>evil element</a>
  22. </div>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.