title: Passing a value in onclick function for loop generated elements
body: <p>I would like to pass a parameter (string from resultset) to an onClick function for a generated link.</p>
  
  <p>Right now I have this: </p>
  
  <pre><code>for (var i=0; i&lt;response.data.length; i++){
        var attend= document.createElement("a");
        var name = response.data[i].name;
        attend.innerHTML="Add event";
        attend.addEventListener("click", function() {saveEvent(name);}, false);
        document.getElementsByClassName("event")[i].appendChild(attend);
  }
  </code></pre>
  
  <p>This results in me always getting the last element name whichever link I click on.</p>