If I may pick your brain? So far, I was able to do the hide and show but the problem is if we click the button for the blue box to be hidden, the red box will go to the place of the blue box. Hence, it may cause confusion.
I want that if we click that button, the blue box will just disappear and the red box should stay put, stay in its original position/location. I hope that makes sense. Your input will be very much appreciated.
// start for the green here -----------------------------------------------------
document.getElementById("button4green").addEventListener("click", function() // made a function to call on onclicking
{
let greenbox = document.getElementById("greendiv")
//now add the condition
if (greenbox.style.display == "none") {
greenbox.style.display = "block";
} else {
greenbox.style.display = "none";
}
});
// end for the green here -----------------------------------------------------
// start for the blue here -----------------------------------------------------
document.getElementById("button4blue").addEventListener("click", function() // made a function to call on onclicking
{
let bluebox = document.getElementById("bluediv")
//assigned a variable to it
//now add the condition
if (bluebox.style.display == "none") {
bluebox.style.display = "block";
} else {
bluebox.style.display = "none";
}
});
// end for the blue here ----------------------------------------------------
// start for the red here ---------------------------------------------------
document.getElementById("button4red").addEventListener("click", function() // made a function to call on onclicking
{
let redbox = document.getElementById("reddiv")
if (redbox.style.display == "none") {
redbox.style.display = "block";
} else {
redbox.style.display = "none";
}
});
#greendiv {
width: 30%;
height: 50%;
background-color: green;
float: left;
}
#bluediv {
width: 30%;
height: 50%;
background-color: blue;
float: left;
}
#reddiv {
width: 30%;
height: 50%;
background-color: red;
float: left;
}
<!------- green -------->
<input type="button" value="GREEN" id="button4green" style="position: absolute; left: 13%;">
<div id="greendiv">
greendiv
</div>
<!------- blue -------->
<input type="button" value="BLUE" id="button4blue" style="position: absolute; Left:43%">
<div id="bluediv">
bluediv
</div>
<!------- red -------->
<input type="button" value="RED" id="button4red" style="position: absolute; Left:74%">
<div id="reddiv">
reddiv
</div>