Last active
December 11, 2015 21:48
-
-
Save BernhardPosselt/4665085 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
for(var i=0; i<10; i++){ | |
$elem = $("<p>"); | |
$elem.click(function(){ | |
alert(i); // alerts 9 every time the element is being clicked | |
}); | |
$(document).append($elem); | |
} | |
// solution | |
for(var i=0; i<10; i++){ | |
$elem = $("<p>"); | |
$elem.click(function(){ | |
function(value){ | |
alert(value); | |
}(i); | |
}); | |
$(document).append($elem); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment