OnClick Event with a Variable

Ok so finally I found this amazing post that answers a question that has been driving me insane the past two days...How can I pass a variable to an onclick event with a link that I just created dynamically in JavaScript. And then I come across this post and it just makes so much sense; why didn't I think of it myself.

Anyway, if you ever have the same question here is the link...
Unobtrusive Javasc#ipt: add onclick function with a variable - Dev Shed

i ---> the iterator
anchor.onclick = (function(i){return function(){deleteOut(i);}})(i);