Skip to content

Instantly share code, notes, and snippets.

@pragmaticobjects
Created September 10, 2011 22:40
Show Gist options
  • Select an option

  • Save pragmaticobjects/1208897 to your computer and use it in GitHub Desktop.

Select an option

Save pragmaticobjects/1208897 to your computer and use it in GitHub Desktop.
Onclick in a loop problem
var myElements = [ /* DOM Collection */ ];
for (var i = 0; i < 100; ++i) {
myElements[i].onclick = function() {
alert( 'You clicked on: ' + i );
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment