Skip to content

Instantly share code, notes, and snippets.

@paulobsf
Created December 9, 2013 23:45
Show Gist options
  • Save paulobsf/7883185 to your computer and use it in GitHub Desktop.
Save paulobsf/7883185 to your computer and use it in GitHub Desktop.
JS Tests
var createButtons = function() {
for(var i = 0; i < 10; i++) {
var btn = document.createElement('button');
var t = document.createTextNode('test ' + i);
btn.appendChild(t);
(function(i) {
btn.addEventListener('click', function() {
alert(i);
});
})(i)
document.getElementsByTagName('body')[0].appendChild(btn);
}
}
createButtons();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment