So I'm creating a button that adds a new <div>
to a group of <div>
tags. It's a fairly complex <div>
with a lot of configuration options that ends up being around 30-40 lines of code.
My questions is basically should I store that HTML for the stock <div>
as a Javascript variable or hide it in the DOM and reference the <div>
via jQuery and set the contents to a variable. There will be a lot of this kind of code in my page so I feared generating tons of HTML with Javascript
var item_html =
'<div>'+
.... 30-40 lines of code .....
'</div>';
$('new_item').on('click',function(){
$('#Container').append(item_html);
});
OR
$('new_item').on('click',function(){
$('#Container').append($('#new_item_html').html());
});