Posted By

stellit on 12/09/08


Tagged

fix cross-browser


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

sulfurito


make your mouse out event works right


 / Published in: JavaScript
 

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...

  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  

You need to login to post a comment.