title: Onclick event is not working on first click
body: <p>When the page loads I need to click the button twice to trigger the <code>onclick()</code> function. After doing so, everything works as expected.</p>
  
  <p>As I am new to this web development field I would highly appreciate the detailed explanation. </p>
  
  <p>Thank you in advance.  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var hamburger = function() {
    var menu = document.getElementById('menuBarSlide');
    if (menu.style.right == "-300px") {
      menu.style.right = "0px";
    } else {
      menu.style.right = "-300px";
    }
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="navMenuItem hamburger" onclick="hamburger()"&gt;
    &lt;span class="ham-icon"&gt;&lt;/span&gt;
    &lt;span class="ham-icon"&gt;&lt;/span&gt;
    &lt;span class="ham-icon"&gt;&lt;/span&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>