I'm trying to toggle the display on an element, and whilst I have used the conditional statement using below of '===' on say an ID of an element, which worked, I cannot get this code to work.
Does anyone know why the condition 'if (smallnavbar[0].style.display === 'none')' doesn't work? Is there a way to make the code work (toggle the display between none and flex)?
Thanks in advance!
function displayMenu(){
var smallnavbar = document.getElementsByClassName("small-navbar-tabs");
if (smallnavbar[0].style.display === 'none') {
smallnavbar[0].style.display = 'flex';
}
else if (smallnavbar[0].style.display === 'flex') {
smallnavbar[0].style.display = 'none';
}
}
==instead of===.===doesn't do any type conversion.smallnavbar, that should shed some light on the situation.