By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,970 Members | 1,668 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,970 IT Pros & Developers. It's quick & easy.

Get Div Id where mouse was clicked

P: 91
I'm trying to get the Div ID that the mouse was clicked in so that if it was not clicked in id ('divContext') then it will hide ('divContext'). What I have right now works perfect in FF but not in IE. The div will not go away even when a link is clicked.

Expand|Select|Wrap|Line Numbers
  1. //see if the focus has been taken off of the div and if so hide it.
  2. function on_down(e)
  3. {
  4.     //alert('test');
  5.     if (e == null) { e = window.event; }
  6.     var evt = e.target || e.srcElement;
  7.     //alert(evt.id);
  8.     if (evt.id != 'divContext' && evt.id != 'aView' && evt.id != 'aComplete')
  9.     {
  10.         if (document.getElementById('divContext').style.display != 'none')
  11.         {
  12.             document.getElementById('divContext').style.display = 'none';
  13.         }
  14.     }
  15. }
  16. // See if a link in the div was clicked.
  17. function on_up(e)
  18. {
  19.     if (e == null) { e = window.event; }
  20.     var evt = e.target;
  21.     //alert(evt.id);
  22.     if (evt.id == 'aView' || evt.id == 'aComplete')
  23.     {
  24.         if (document.getElementById('divContext').style.display != 'none')
  25.         {
  26.             document.getElementById('divContext').style.display = 'none';
  27.         }
  28.     }
  29. }
  30.  
  31. onload=function()
  32. {
  33.     onmousedown = on_down;
  34.     onblur = on_down;
  35.     onmouseup = on_up;
  36. }
  37.  
Anyone know why this will not work in IE?
May 2 '08 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
For the on_up function, you forgot the srcElement part (which you have in the on_down) function.
May 3 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.