I have a situation where I have a load of JSON I need to process, and for each "data" item, output this on the page as a list item. This is fine, however I am conscious of the proper way to do this.
For example, one way which I can only think of is:
$.each(json.data, function(key, value) {
$('ul').prepend("<li><div class='name'>" + value.name + "</div>...<li>");
});
Now this works, however if I have multiple layers of divs and other elements it's just going to get messy. I could make it look better in the code by multi-lining it, but that's still a horrible way to maintain it.
How do I get around this and do/present it properly?
Prehaps a template in another file which I load in, then assign HTML/text to specific elements?