Note that in loops, the variable i is not "scoped" to the loop block even though the keyword var is used before the variable name. Scope is covered in more depth ...
learn.jquery.com