If you're initialising idCounter to 1, then the end condition in your for loop is already met, so it won't loop...is that the problem?
I think the op has an infinite loop because
is being incremented as well on each loop iteration and so
will always be < idCounter.
But imo for something relatively basic, it's easier without jquery.