Javascript – Dynamically assign onclick event in the loop

You’ll have to do something like this:

btnShow.onclick = (function(opt) {
    return function() {
       showParam(opt);
    };
})(arrOptions[i]);

Leave a Comment