<button class="but">click</button>
<div id="div" style="display: none; background: lightgreen">
<button>button</button>
text
</div>
<script>
window.onload = function () {
function sh(elem) {
if (elem.style.display != 'block') {
elem.style.display = 'block';
} else {
elem.style.display = 'none';
}
}
var div = document.getElementById('div');
document.body.onclick = function (e) {
e = e || event;
var target = e.target || e.srcElement;
if (target.className == 'but') {
sh(div);
} else {
while (target && target != div) {
target = target.parentNode;
}
if (target != div) {
div.style.display = 'none';
}
}
}
}
</script>