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