<html> 
<head> 
<script> 
if(typeof(HTMLElement)!="undefined")
HTMLElement.prototype.contains=function(obj)
{
  if(obj==this)return true;
  while(obj=obj.parentNode)if(obj==this)return true;
  return false;

document.onmousedown=function(e) 

e=e||event;
if(!dd.contains(e.target||e.srcElement))
  dd.style.display="none"; 

</script> 
</head> 
<body> 
<div id="dd" style="border:solid 1px red; backgroun-color:#ccc"> 
asdfasdfad 
</div> 
</body> 
</html>