How do I hide the information when I toggle on another button? Right now, if there is already information displayed at the bottom and I click on another button, the information just appears at the bottom instead.
function myClick() {
var x = document.getElementById("myDIV");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
}
function myClick2() {
var x = document.getElementById("myDIV2");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
}
#myDIV,
#myDIV2 {
display: none;
}
.wrapper {
display: flex;
}
.col {
display: inline-block;
width: 50%;
padding: 2px 8px;
}
.box {
display: flex;
background-color: #f4f4f4;
}
<div class="wrapper">
<div class="col">
<div class="box" onclick="myClick()">Box</div>
</div>
<div class="col">
<div class="box" onclick="myClick2()">This is a box</div>
</div>
</div>
<div id="myDIV">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. </p>
</div>
<div id="myDIV2">
This is my DIV element.
</div>