Is there a general best practice for creating somewhat complex HTML elements in jQuery? I\'ve tried a few different ways.
First I tried using createElement and chaining
Since HTML5 there's the tag.
$(function () {
// Get template
var template = $("#template").html();
// Create a new row from the template
var $row = $(template);
// Add data to the row
$row.find("td[data-template='firstName']").text("Foo");
$row.find("td[data-template='lastName']").text("Bar");
// Add the row to the table
$("#table").append($row);
});
Firstname
Lastname