I have a DIV (box) that’s toggled (with JavaScript) between ‘display: block’ and ‘display: none’ when clicking another DIV (text). There is also a close option (‘display: none’) in that box.
There are also other DIVs (Google Translate drop down menu for exemple) in that box, that I want to be clickable without the box closing.
So, how do I make the box close (with CSS: ‘display: none’) when clicking OUTSIDE of that box? How can I implement that in the code below?
A simplification and demonstration of my setup: JSFiddle
JavaScript and HTML (cleaned out excessive data):
<div id="toggle-container">
<div id="toggle-text"> <p class="notranslate"><a href="#"
onclick="toggle_visibility('toggle-box');">TOGGLE BOX</a></p>
<script type="text/javascript">
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
</script>
<div id="toggle-box">
<div id="box-content">..with other divs...</div>
<div id="translate-box-close">
<a onclick="document.getElementById('toggle-box')
.style.display='none';return false;" href="">CLOSE BOX</a></div>
</div>
</div>
</div>
CSS (cleaned out excessive data):
#toggle-container {
}
#toggle-text {
}
#toggle-box {
position: ABSOLUTE;
display: NONE;
}
#box-content {
}