Hello!
Question on jQuery Templates plugin. Is it possible to place the template itself not in the HTML code, but inside the JavaScript code?
For example. In the classic version looks like this: HTML:
<script id="tpl" type="text/x-jquery-tmpl"> <div class="test"> <h2> Переменная равна: ${title} </h2> </div> </script> <div id="test1"></div> Js:
$(function () { $("#tpl").tmpl({ "title" : "Hello World" }).appendTo('#test1'); }); I would not like to have text/x-jquery-tmpl templates in the HTML code of the page. Therefore, I transferred the template part to the JS code:
$(function () { $("<div class="test"><h2>Переменная равна: ${title}</h2></div>").tmpl({ "title" : "Hello World" }).appendTo('#test1'); }); But an error occurs!
Tell me, please, what is wrong and how can I transfer a template from HTML to JavaScript code.
Thank!