var tableArr = [ "

line 1

", "

line 2

", "

line 3

" ], key = 0; for (key; key < tableArr.length; key = key + 1) { (function (k) { $('#line' + k).click(function (event) { event.preventDefault(); $('#container').html(tableArr[k]); }); }(key)); }