stackoverflow-javascript-if-statement-with-boolean
HTML
<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {
width: 500px;
height: 500px;
background-color: lightblue;
display: none;
}
</style>
</head>
<body>
<p>Click the "Try it" button to set the display property of the DIV element:</p>
<button onclick="myFunction()">Try it</button>
<div id="myDIV">
This is my DIV element.
</div>
<p><b>Note:</b> The element will not take up any space when the display property set to "none".</p>
<script>
var div_aperto = false;
function myFunction(div_aperto) {
if (div_aperto) {
div_aperto = false;
document.getElementById("myDIV").style.display = "none";
} else {
div_aperto = true;
document.getElementById("myDIV").style.display = "block";
}
}
</script>
</body>
</html>