0

I'm a newbie into js and I'm writing a js code to close and open a side bar.The required function is assigned in to an anchor and the status of the side bar is indicated by the variable "closed". The openNav() function and closeNav() function works fine when they are assigned in to the anchor separately. But when the "transNav()" function is called it doesn't work. this is my code.

<script>

var closed = 1;

function openNav() {
  document.getElementById("mySidebar").style.width = "250px";
  document.getElementById("main").style.marginLeft = "250px";
}

function closeNav() {
  document.getElementById("mySidebar").style.width = "50px";
  document.getElementById("main").style.marginLeft= "50px";
}

function transNav() {
    if (closed==1){
        openNav();
        closed=0;
    }else if (closed==0){
        closeNav();
        closed=1;
    }
}
</script>

I used the triple equals operator also , but it didn't work What is mistake that I have done? Is it in the variables or function calling?

0 Answers0