Skip to content

Instantly share code, notes, and snippets.

@mariyadiminsky
Created May 3, 2016 07:30
Show Gist options
  • Save mariyadiminsky/146eb26882091203bf65a1a33ca7daf7 to your computer and use it in GitHub Desktop.
Save mariyadiminsky/146eb26882091203bf65a1a33ca7daf7 to your computer and use it in GitHub Desktop.
// with var. See example live: https://jsfiddle.net/maasha/gsewf5av/
for(var i= 0; i<30; i++){
var div = document.createElement('div');
div.onclick = function() {
alert("you clicked on a box " + i);
};
document.getElementsByTagName('section')[0].appendChild(div);
}
// with let. See example live: https://jsfiddle.net/maasha/xwrq8d5j/
for(let i=0; i<30; i++) {
var div=document.createElement(‘div’);
div.onclick = function() {
alert("you clicked on a box " + i);
};
document.getElementsByTagName('section')[0].appendChild(div);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment