I am writing an application that uses handlebars.js but The example code on their website uses JQuery so as do many other online resources. However, I want to simply compile and render a handlebars template using vanilla js.
This is the HTML template
<script id="entry-template" type="text/x-handlebars-template">
<div class="entry">
<h1>{{title}}</h1>
<div class="body">
{{body}}
</div>
</div>
</script>
The JS I have for the compilation is below, as suggested in the answer to a similar question here Does Handlebars require jQuery
var source = document.getElementById('entry-template').innerHTML;
var template = Handlebars.compile(source);
Assume my JSON is stored in a variable called myData.
When it comes to rendering the template with JQuery you can simply do
$('#data-section').append(template(myData));
But I want to use vanilla JS so I'm doing this:
var compiledHTML = template(myData);
var dataContainer = document.getElementById('data-section');
dataContainer.appendChild(compiledHTML);
but I get the error
Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
How do I get this to work?