but need to close that div layer when i click any where else in the body
I presume you mean any element other than the DIV.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<script type="text/javascript">
/*<![CDATA[*/
function myDiv(){
var obj=document.getElementById('myDiv'),e=window.event||arguments.callee.caller.arguments[0],eobj=e.target?e.target:e.srcElement;
while (eobj.parentNode){
if (eobj==obj){
return false;
}
eobj=eobj.parentNode;
}
obj.style.display=obj.style.display == 'none'?'block':'none'
}
function Init(){
document.body.onclick=function(){ myDiv(); }
}
if (window.addEventListener){
window.addEventListener('load',Init, false);
}
else if (window.attachEvent){
window.attachEvent('onload',Init);
}
/*]]>*/
</script>
</head>
<body bgcolor="green">
<div id="myDiv" style="width:200px;height:200px;background-Color:red;" ></div>
<div style="width:200px;height:200px;background-Color:blue;" ></div>
</body>
</html>
Bookmarks