ARASH ARASH - 1 year ago 55
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.

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";


<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>

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download