Based on Nicholas Zaka's book 'Maintainable JavaScript', I understand that the best way to put a small HTML template in my page is to add something like:
<script type="text/x-templates" class="templates">
<div class="template1"> ... </div>
<div class="template2"> ... </div>
...
</script>
I like this approach better than placing my templates in the <body>
and hide them using css because these would still be displayed in browsers like dillo.
The way I'm currently grabbing them with jQuery is this:
var $templates = $('<div/>').append($('.templates').text()).children();
Things that I tried that didn't work are:
var $templates = $('.templates');
var $templates = $($('.templates').text());
var $templates = $($('.templates').html());
The solution I have now works but it doesn't seem to me very elegant. What would be the best way to do this?