"click" for a dynamically created link isn't getting triggered
<p>I want to add a link dynamically and attach "onclick" event on it. Here's a simplified version of what I have:</p>

<pre><code>for (var i = 0; ....) {
    var a1 = document.createElement("a");
    a1.innerHTML = "My link123";
    a1.addEventListener("click", function(event) {
      myFunc(someArray[i].property1, event);
      // alert("test123");
    });

    var p1 = document.createElement("p");
    var sp1 = document.createElement("span");
    //..........

    divContainer.innerHTML += a1.outerHTML + p1.outerHTML + sp1.outerHTML;
 }
</code></pre>

<p>But it doesn't trigger the "click" event when I click on it.</p>

<p><strong>update</strong>:</p>

<p>after it's created and I click on it, I get:
<code>myFunc(someArray[i].property1, event); -- Cannot read property 'property1' of undefined</code></p>

<p>I guess it's something related to how clojures are evaluated.</p>

<p><strong>update2</strong></p>

<p>I've tried this:</p>

<pre><code>a1.addEventListener("click", function(event) {
  (function(i2){
    myFunc(i2, event);
  })(myArray[i].property1);
});
</code></pre>

<p>But it said at runtime when I clicked on it "property1 isn't defined"; How can I fix that?</p>