I am looking for a way to implement a function that will hide a specific div when I click outside of its area. The div is initially set to Position: none
and can be made visible using the following function:
Div Element:
<div id="TopBarBoxInfo1" onclick="showSerachOptions('BoxBox');" >
</div>
Javascript Function:
function showSerachOptions(element){
var element = document.getElementById(element);
if(element.id == 'Box'){
if(element.style.display == 'none'){
element.style.display = 'block';
}
else{
element.style.display = 'none';
}
}
}
Now, I need help with creating a new function that will close the div when the mouse pointer is clicked outside of its area. Any detailed explanation would be greatly appreciated as I am a beginner in javascript!