more advanced system (without plugins) https://stackoverflow.com/questions/17884300/how-can-i-use-templates-with-jquery-without-additional-plugins jsFiddle: http://jsfiddle.net/94jDr/
String.prototype.fillTemplate = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};
var cardTemplate = $("#cardTemplate").html();
var template = cardTemplate.fillTemplate("http://example.com", "Link Title");
$("#container").append(template);
<!-- template -->
<script type="text/template" id="cardTemplate">
<span><a href="{0}">{1}</a></span>
</script>
<!-- output -->
<div id="container"></div>