Skip to content

Instantly share code, notes, and snippets.

@teaualune
Created February 25, 2014 16:44
Show Gist options
  • Save teaualune/9212728 to your computer and use it in GitHub Desktop.
Save teaualune/9212728 to your computer and use it in GitHub Desktop.
jQuery event binding in array
var tableArr = [
"<p>line 1</p>",
"<p>line 2</p>",
"<p>line 3</p>"
],
key = 0;
for (key; key < tableArr.length; key = key + 1) {
(function (k) {
$('#line' + k).click(function (event) {
event.preventDefault();
$('#container').html(tableArr[k]);
});
}(key));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment