Good Day,
I have an ASP.NET MVC app that I'm working on and have a partial view with one row of data.
<div class="row paymentRow">
<div class="col-xs-4">Additional Invoices</div>
<div class="col-xs-8"><input type="text" style="width: 100%"/></div>
</div>
I have a button that when clicked, it adds additional rows to the DOM after the after the last div with the class "row paymentRow".
<div class="btn-group" role="group" aria-label="...">
<button type="button" id="Add">Add Row</button>
<button type="button" id="Ok">Ok</button>
<button type="button" id="Cancel">Cancel</button>
</div>
The jQuery to add the additional row works:
$(function() {
$("#Add").click(function(e) {
e.preventDefault();
var row = '<div class="row paymentRow">' +
'<div class="col-xs-4"> </div>' +
'<div class="col-xs-8"><input type="text" style="width: 100%"/></div>' +
'</div>';
$("div.modalUploadWidth div.row:last").after(row);
});
});
My question is:
Is there a cleaner way to represent the HTML that is being dynamically constructed and assigned to row? I'm not a big fan of magic strings like this. Not only that, but there will be multiple instances of where I need to inject javascript into the DOM.
I know that I can put the string into a Resource and access it from there. I also know that Handlebars can do this by storing the javascript template into an external file and binding the contents of the external file to the DOM.
I'm trying to find alternatives I may be overlooking.
TIA,
coson