Hey guys, im quite stucked with a small script here, Im sure someone can help me get it solved.
Im trying to make a popup div (when link is clicked) which can be closed (visibility: none) by clicking anywhere outside the div, I got that part done, but now if I add more div's inside the popup div and click over those div's the popup gets closed,
I made my script based on a couple scripts i found on google
Code:
<head>
<script type="text/javascript">
document.onclick=check;
var hza;
function check(e) {
var target = (e && e.target) || (event && event.srcElement);
var mainobj = document.getElementById('div1');
var linkobj = document.getElementById('link');
if(target!=mainobj&&target!=linkobj){
if (hza && hza.style) {
hza.style.display = 'none'; }
}
}
function toggle(layer_ref) {
if (document.getElementById) {
hza = document.getElementById(layer_ref);
} else if (document.all) {
hza = document.all['layer_ref'];
}
if (hza && hza.style) {
hza.style.display = (hza.style.display == '')? 'none':'';
}
}
</script>
<a href="#" onclick="toggle('div1');return false;" id="link"></a>
<div id="div1" style="position: relative; margin: 0 auto; width: 800px; display: none; border: dotted;">
<div style="width: 800px; height: 35px; background-color: #000;"></div><br /><br /><br /><br />
</div>
Any suggestion greatly appreciated.