Skip to content

Instantly share code, notes, and snippets.

@yasu
Created January 20, 2012 12:49
Show Gist options
  • Select an option

  • Save yasu/1647225 to your computer and use it in GitHub Desktop.

Select an option

Save yasu/1647225 to your computer and use it in GitHub Desktop.
// Make a function that assigns event handler functions to an array of nodes the right way.
// When you click on a node, an alert box will display the ordinal of the node.
var add_the_handlers = function (nodes) {
var i;
for (i = 0; i < nodes.length; i += 1) {
nodes[i].onclick = function (i) {
return function (e) {
alert(i);
};
}(i);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment