title: Javascript onclick function is called immediately (not when clicked)?
body: <p>I am trying to create a link, which looks and feels like an <code>&lt;a&gt;</code> tag item, but runs a function instead of using the href.</p>
  
  <p>When I try to apply the onclick function to the link it immediately calls the function regardless of the fact that the link was never clicked. Any attempt to click the link thereafter fails.</p>
  
  <p>What am I doing wrong?</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;div id="parent"&gt;
      &lt;a href="#" id="sendNode"&gt;Send&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Javascript</strong></p>
  
  <pre><code>startFunction();
  
  function secondFunction(){
      window.alert("Already called!?");
  }
  
  function startFunction() {
      var sentNode = document.createElement('a');
          sentNode.setAttribute('href', "#");
          sentNode.setAttribute('onclick', secondFunction());
        //sentNode.onclick = secondFunction();
          sentNode.innerHTML = "Sent Items";
  
      //Add new element to parent
      var parentNode = document.getElementById('parent');
      var childNode = document.getElementById('sendNode');
      parentNode.insertBefore(sentNode, childNode);
  }
  </code></pre>
  
  <p><a href="http://jsfiddle.net/52rcrww4/1/" rel="noreferrer">JsFiddle</a></p>
  
  <p>As you can see I tried two different ways of adding this onclick function, both of which have the same effect.</p>