Skip to content Skip to sidebar Skip to footer

Calling Onclick With Local Variable

First, apologies for asking something that must be answered here somewhere (I've been looking!) I want to do this: var i; for (i = 0; i < 5; i++) { ... // Add an anchor to t

Solution 1:

a.onclick = (function(i) { returnfunction() {goog.bind.....}; })(i);

That creates a new closure in which the value of i is fixed.

Solution 2:

Something like this may work better for you:

a.onclick = function() {
    doSomething(this, i)
}

Post a Comment for "Calling Onclick With Local Variable"