Created
October 24, 2016 12:33
-
-
Save amici-fos/fe71a47eeb6110168b5aa8d3c7958a36 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// clear the screen for testing | |
document.body.innerHTML = ''; | |
var nums = [1,2,3]; | |
// Let's loop over the numbers in our array | |
for (var i = 0; i < nums.length; i++) { | |
// This is the number we're on... | |
var num = nums[i]; | |
// We're creating a DOM element for the number | |
var elem = document.createElement('div'); | |
elem.textContent = num; | |
// ... and when we click, alert the value of `num` | |
elem.addEventListener('click', (function(numCopy) { | |
return function() { | |
alert(numCopy); | |
}; | |
})(num)); | |
document.body.appendChild(elem); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment