title: Javascript run once using if condition?
body: <p>What I'm trying to do is run the if statement once only and disable the statement. In my code if I click the button consecutively the if statement still get rendered. Why is that?</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;button onclick="appendMsg()"&gt;submit&lt;/button&gt;
  &lt;div id="wrapper"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>function appendMsg(){
  
    var triggerOnceforShare = true;
  
    if(triggerOnceforShare){
       triggerOnceforShare = false;
      document.getElementById('wrapper').innerHTML+=triggerOnceforShare + "&lt;br /&gt;"
      console.log(triggerOnceforShare);
    }
  
  }
  </code></pre>
  
  <p>codepen:
      <a href="http://codepen.io/vincentccw/pen/uoBkI" rel="nofollow">http://codepen.io/vincentccw/pen/uoBkI</a></p>