0

Hey, I have another incredibly simple JavaScript problem... I have a div that is shown when a link is clicked on. That is no problem and working fine. I then need the div to be hidden when the mouse is clicked anywhere on the page. Again, no problem in FF,Chrome,Safari and Opera but not in IE and it is really doing my head in now(!)

Here is the code

document.onmouseup = function()
{
  hide();
}

I have tried many variations on the theme, none of which so far work, even having the function just give an alert will not work at all in IE. And I am running out of ideas!

Any help would be appreciated immensly. Cheers.

sje397
  • 41,293
  • 8
  • 87
  • 103
rich
  • 1,224
  • 1
  • 19
  • 36
  • 1
    More code please. The problem is obviously not in the bit you posted. Where is the script in relation to the element, and what is the content of the hide function? – sje397 Aug 19 '10 at 10:20
  • The hide(); function is simply function hide() { elm = document.getElementById("DropdownShare0") if (elm.style.display == "block") { elm.style.display = 'none' } } The actual page itself is pretty huge, I can't post it here to be honest. the script is in the head of the page. I'm beginning to think that this could be to do with other things on the page. – rich Aug 19 '10 at 10:24

1 Answers1

0

I think the problem may be in your hide function..

If you haven't created the div with the id DropdownShare0 with some default display style, the code

"if (elm.style.display == "block")" will be false because if none is set when creating element it will return 'undefined'

So check that too..

Vijay
  • 5,331
  • 10
  • 54
  • 88
  • The script is only included if the element is on the page, and the element has a default display: none. This is then changed once the link has been clicked and some script has been fired to change the display to display:block. – rich Aug 19 '10 at 10:41