Regarding Div Display

Posted by user71723 on Stack Overflow See other posts from Stack Overflow or by user71723
Published on 2010-06-11T05:56:16Z Indexed on 2010/06/11 6:02 UTC
Read the original article Hit count: 216

Filed under:
|

Hi to all,

When i click on button,one div is showing..whenever i click on the body,that div will be hide.

How can we achieve this functionality .. i write one code is as below.

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">
function HideSubMenus(e)
{
 var targ;
 if (!e) var e = window.event;
 if (e.target) targ = e.target;
 else if (e.srcElement) targ = e.srcElement;
 if (targ.nodeType == 3) // defeat Safari bug
  targ = targ.parentNode;
 for (var i=0; i!=5; i++) {
  if (!targ) {
   break;
  } else if (targ.className=="divclass") {
   return;
  }
  targ = targ.parentNode;
 }

 if(document.getElementById("showdivid"))
 {
  document.getElementById("showdivid").style.display='';
 }
}
</script>
</head>

<body onclick="HideSubMenus(event);">
<input type="button" name="button" value="Click ME" onclick="document.getElementById('showdivid').style.display='';" />
<div id="showdivid" class="divclass" style="display:none;">
TeSt DIV
</div>
</body>
</html>

regards raj

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about divs