Last active
December 11, 2015 21:48
-
-
Save BernhardPosselt/4665085 to your computer and use it in GitHub Desktop.
Revisions
-
BernhardPosselt revised this gist
Jan 29, 2013 . 1 changed file with 12 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,18 @@ 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); } -
BernhardPosselt created this gist
Jan 29, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ for(var i=0; i<10; i++){ $elem = $("<p>"); $elem.click(function(){ alert(i); }); $(document).append($elem); }