Adding HTML DOM template
There isn't much to refactor here and you already identified the problem scope. 

You are much better off with a JavaScript template engine. 

I won't be too opinionated here, but popular options are: 


http://handlebarsjs.com/
https://github.com/janl/mustache.js/
http://documentcloud.github.io/underscore/#template
http://ejohn.org/blog/javascript-micro-templating/