ARASH ARASH - 4 months ago 10
Javascript Question

why the else if dosn't work

I'm working on a website and I want when a user clicks the menu it appears or hides but the else if in function onclick() does not work.

<script>
function oclick() {
if (document.getElementById("smenu").style.display ="none"){
document.getElementById("smenu").style.display ="block";
} else if (document.getElementById("smenu").style.display ="block"){
document.getElementById("smenu").style.display ="none";
}

}

</script>
<div class="main">
<div id="menu">
<ul class="Header-ul">
<li ><a id="w" href="Home.html">WWW</a></li>
<li ><a id="ww" href="Home.html">TH</a></li>
<li ><a onclick="oclick()" style="cursor: pointer" >learn</a>
<ul id="smenu" class="sub-menu">
<li><a href=" ~/Home/countries">learn HTML</a></li>
<li><a href=" ~/Home/countries">learn CSS </a></li>
<li><a href=" ~/Home/countries">learn JAVASCRIPT </a></li>
<li><a href=" ~/Home/countries">learn PHP </a></li>
</ul>
</li>
</ul>
</div>
</div>

Answer

You would use == in conditionals. Also, wrong category.