In plain English, what is it you are trying to do? A picture might be helpful.
This code seems way over-complicated. I can't reverse-engineer
your intent from the code.
Please don't use alerts for debugging - they can break working
code, and make certain not-working code work! Use console.log()
instead, and then watch the Javascript console.
When I see a bunch of IDs with numbered suffixes, I see unnecessary complication.