I like the idea of templating this in some way, as concatenating HTML using JavaScript does feel messy. A better thing to check out is EJS or Handlebars.