There is something I can't understand. I have a basic function with 2 buttons, when clicking the first it should hide the other one & reveal it if it was previously hidden.
I use a style.display test but unless I use only "=" in my test, it fails. I don't get why. Any hint please?
Here is the code with a "mistake" that works:
function reduce() {
if (document.getElementById("B5").style.display = "block")
{
document.getElementById("B5").style.display = "none";
}
}
<button id="B1" onclick="reduce()">Button 1</button>
<button id="B5" >Button 2 (to hide)</button>
Here is the one that should work but does not:
function reduce() {
if (document.getElementById("B5").style.display == "block")
{
document.getElementById("B5").style.display = "none";
}
}
<button id="B1" onclick="reduce()">Button 1</button>
<button id="B5" >Button 2 (to hide)</button>
Where do I get it wrong? Thanks