CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Show a hidden div by clicking anywhere on the page (http://www.codingforums.com/showthread.php?t=170776)

FeralUK 07-03-2009 04:28 PM

Show a hidden div by clicking anywhere on the page
 
I got this script of the internet that toggles a hidden div on/off. I have converted this script into a drop down menu so the hidden div is the second level of the menu and is floating above the rest of the content. Can anyone please show me how to go about modifying the script so that the hidden div is hidden again when i click anywhere on the page other than the div itself instead of having to toggle it. Thanks. ps. hope this wasn't too confusing.

HTML
Code:

<div id="mydiv"><a href="javascript:unhide('mydiv2');">Click here to show content</a>
</div>
<div id="mydiv2" class="hidden"> this hidden text will show when the link is pressed
</div>

CSS
Code:

.hidden { display: none; }
.unhidden { display: block; }

JAVASCRIPT
Code:

<script type="text/javascript">
function unhide(divID) {
  var item = document.getElementById(divID);
  if (item) {
    item.className=(item.className=='hidden')?'unhidden':'hidden';
  }
}
</script>

Thanks

ckeyrouz 07-03-2009 04:45 PM

Add the onblur event of the div itself:
<div id="mydiv" onblur='unhide("mydiv")'><a href="javascript:unhide('mydiv2');">Click here to show content</a>
</div>

FeralUK 07-03-2009 07:42 PM

Quote:

Originally Posted by ckeyrouz (Post 834975)
Add the onblur event of the div itself:
<div id="mydiv" onblur='unhide("mydiv")'><a href="javascript:unhide('mydiv2');">Click here to show content</a>
</div>

Hey,
This didn't seem to work... Any other suggestions.
Thanks.

ckeyrouz 07-03-2009 09:46 PM

Sorry for that put the blur event on the anchor like this:
<div id="mydiv"><a onblur='unhide("mydiv")' href="javascript:unhide('mydiv2');">Click here to show content</a>
</div>

FeralUK 07-03-2009 10:20 PM

Thanks. Solved it now.

ckeyrouz 07-03-2009 10:23 PM

If what I said helped solved your problem please thank me using the thank button.
I apologize if I appear rude but I am trying to increase my credit in this forum.

Thank you.


All times are GMT +1. The time now is 10:24 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.