Skip to content

Instantly share code, notes, and snippets.

@internetbird
Created February 9, 2016 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save internetbird/0585f554474a564d9f0f to your computer and use it in GitHub Desktop.
Save internetbird/0585f554474a564d9f0f to your computer and use it in GitHub Desktop.
var list = document.getElementById("list");
for (var i = 1; i <= 5; i++) {
var item = document.createElement("LI");
item.appendChild(document.createTextNode("Item " + i));
let j = i;
item.onclick = function (ev) {
console.log("Item " + j + " is clicked.");
};
list.appendChild(item);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment