title: onclick event is triggered before an element is clicked
body: <p>This is the code that I have with <code>onclick</code> event listener.</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>function makeSizer(size) {
      alert(size)
      document.body.style.fontSize = size + 'px';
  }
  
  document.getElementById('size-12').onclick = makeSizer(14);
  document.getElementById('size-14').onclick = makeSizer(16);</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>body {
    font-family: Helvetica, Arial, sans-serif;
    font-size: 12px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>    &lt;p&gt;Some paragraph text&lt;/p&gt;
  
      &lt;a href="#" id="size-12"&gt;12&lt;/a&gt;
      &lt;a href="#" id="size-14"&gt;14&lt;/a&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>However, I have no idea why once browser is loaded, the clicked event is triggered immediately or before I actually click the link. Could you help me explain this.</p>
  <p>One solution that I got is to use closure like below by returning a function. I wonder if you have any others?</p>
  <pre><code>function makeSizer(size) {
      return function (){
          alert(size)
      document.body.style.fontSize = size + 'px';
      }       
  }
  </code></pre>
  <p>By the way, there may be a dulplicate <a href="https://stackoverflow.com/questions/32742543/onclick-event-is-triggered-without-clicking">here</a>. However, I'm seeking more general explanation/discussion than debugging.</p>
  <p>Thank you.</p>