<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
#div1{
width: 100px;
height: 100px;
background-color: aquamarine;
display: none;
}
</style>
</head>
<body>
<div id="div1">
</div>
<input type="button" name="btn" id="btn" value="show/hide" />
<script type="text/javascript">
var div1 = document.getElementById("div1");
var btn = document.getElementById("btn");
btn.onclick = function(){
div1.style.display = "block";
alert("show div");
event.cancelBubble = true;
}
document.onclick = function(){
div1.style.display = "none";
alert("hide div");
}
</script>
</body>
</html>