var should be declared outside of the for loop. Can you please run jshint on your code?