JSFiddle - React, Tailwind, and code Playground
by Reiot
HTML
<script src="http://github.com/jquery/jquery-tmpl/raw/master/jquery.tmpl.js"></script>
<script id="my-tmpl" type="text/x-jquery-tmpl">
<div class="content">
<h4>${title}</h4>
<p>${message}</p>
</div>
<div class="buttonset">
<button class="good">Good</button>
<button class="bye">bye</button>
</div>
</script>
<div id="placeholder"></div>
JavaScript
$(function() {
var data = {
title: 'Hello',
message: 'World',
buttons: {
good: function() {
alert('good');
},
bye: function() {
alert('bye');
}
}
};
var $tmpl = $('#my-tmpl').tmpl(data);
for (var i = 0; i < data.buttons.length; i++) {
var cb = data.buttons[i];
var $button = $('<button>').click(function() {
cb();
});
$('div.buttonset', $tmpl).append($button);
}
$tmpl.appendTo('#placeholder');