you should build the html off the DOM and append it after the structure is complete, see e.g. http://ejohn.org/blog/dom-documentfragments/

atm you change elements which are already part of the DOM and therefore appendChild will be slow