The scenario is quite common, you have a container div and some html to append inside the container:
for ( var i = 0; i < 5; i++ ) {
$('.container-list').append('<div class="item">ITEM ' + i + ' </div>');
}
Example: http://jsfiddle.net/55og08za/
The html to append is dynamic, so there are certain parts of it that changes. The code works, but is very ugly and difficult to maintain if the html is long, mixing html inside javascript is not the best. Also as the content is dynamic I can have a field with quotes or special chars that will break my code, so yes, I will need to escape the strings before, but as you go the code just become more and more ugly.
Is there a way to clean this up maybe with a more object oriented approach?