title: Using a Variable & Loop to Create "onclick" Functions
body: <p>I am trying to use a for loop to generate onclick functions for each of my 4 links below. Right now it doesn't work at all and I am unsure why?</p>
  
  <p>Fiddle: <a href="http://jsfiddle.net/7WYfF/" rel="nofollow">http://jsfiddle.net/7WYfF/</a></p>
  
  <pre><code>&lt;p&gt;&lt;a href="#" id="link0"&gt;Link0&lt;/a&gt;&lt;/p&gt;
  &lt;p&gt;&lt;a href="#" id="link1"&gt;Link1&lt;/a&gt;&lt;/p&gt;
  &lt;p&gt;&lt;a href="#" id="link2"&gt;Link2&lt;/a&gt;&lt;/p&gt;
  &lt;p&gt;&lt;a href="#" id="link3"&gt;Link3&lt;/a&gt;&lt;/p&gt;
  
  &lt;script&gt;
  for (var i = 0; i &lt; 3; i++) {
      var temp = "link" + i;
  
      [temp].onclick = function () { 
          alert("You just clicked link: " + i);
      };
  }
  &lt;/script&gt;
  </code></pre>