title: JavaScript (Have one button open and close something)
body: <p>I currently have a hamburger menu and when you click on the hamburger, it will turn into an x. I want it so that when you click on the hamburger, it will open the menu and if you click the x, it will close the menu.</p>
  
  <p>This is my code so far.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;style&gt;
  body {
      font-family: "Lato", sans-serif;
  }
  
  .sidenav {
      height: 100%;
      width: 0;
      position: fixed;
      z-index: 1;
      top: 0;
      left: 0;
      background-color: #111;
      overflow-x: hidden;
      transition: 0.5s;
      padding-top: 60px;
  }
  
  .sidenav a {
      padding: 8px 8px 8px 32px;
      text-decoration: none;
      font-size: 25px;
      color: #818181;
      display: block;
      transition: 0.3s
  }
  
  .sidenav a:hover, .offcanvas a:focus{
      color: #f1f1f1;
  }
  
  .closebtn {
      position: absolute;
      top: 0;
      right: 25px;
      font-size: 36px !important;
      margin-left: 50px;
  }
  
  #main {
      transition: margin-left .5s;
      padding: 16px;
  }
  
  @media screen and (max-height: 450px) {
    .sidenav {padding-top: 15px;}
    .sidenav a {font-size: 18px;}
  }
  .container {
      display: inline-block;
      cursor: pointer;
  }
  
  .bar1, .bar2, .bar3 {
      width: 35px;
      height: 5px;
      background-color: #333;
      margin: 6px 0;
      transition: .9s;
  }
  
  .change .bar1 {
      -webkit-transform: rotate(-45deg) translate(-9px, 6px) ;
      transform: rotate(-45deg) translate(-9px, 6px) ;
  }
  
  .change .bar2 {opacity: 0;}
  
  .change .bar3 {
      -webkit-transform: rotate(45deg) translate(-8px, -8px) ;
      transform: rotate(45deg) translate(-8px, -8px) ;
  }
  &lt;/style&gt;
  &lt;body&gt;
  
  &lt;div id="mySidenav" class="sidenav"&gt;
  
    &lt;a href="#"&gt;...&lt;/a&gt;
    &lt;a href="#"&gt;...&lt;/a&gt;
    &lt;a href="#"&gt;...&lt;/a&gt;
    &lt;a href="#"&gt;...&lt;/a&gt;
  &lt;/div&gt;
  
  &lt;div id="main"&gt;
    &lt;span style="cursor:pointer" onclick="openNav(); closeNav()&gt;
  &lt;div class="container" onclick="myFunction(this)"&gt;
    &lt;div class="bar1"&gt;&lt;/div&gt;
    &lt;div class="bar2"&gt;&lt;/div&gt;
    &lt;div class="bar3"&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;/span&gt;
  &lt;/div&gt;
  
  &lt;script&gt;
  function openNav() {
      document.getElementById("mySidenav").style.width = "250px";
      document.getElementById("main").style.marginLeft = "250px";
  }
  
  function closeNav() {
      document.getElementById("mySidenav").style.width = "0";
      document.getElementById("main").style.marginLeft= "0";
  }
  function myFunction(x) {
      x.classList.toggle("change");
  }
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>