I have an element with an id of "sd-nav-bar" with display: inline-block,
and I have a button that (after clicking on it) will hide that element if it is shown and vice versa using hider function.
but the hider function which contains two Ifs didn't work at all.
let hider = () => {
let nav = document.querySelector('#sd-nav-bar');
if( nav.style.display == 'inline-block' ) {
nav.style.display = 'none'
}
else if( nav.style.display == 'none' ) {
nav.style.display = 'inline-block';
};
}
and after i replaced the 2nd if by 'else statment' it worked, the code that woked is :
let hider = () => {
let nav = document.querySelector('#sd-nav-bar');
if( nav.style.display == 'inline-block' ) {
nav.style.display = 'none'
}
else {
nav.style.display = 'inline-block';
}
};
So why is this happening ? is the second IF wrong? or i just have to use else statment here and why ?