HTML
<body>
<p>Click "Add" button</p>
<button id="btn-add">Add</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/2.3.0/mustache.min.js"</script>
<script id="my-template" type="x-tmpl-mustache">
{{#users}}
<div>
<span class="name">{{name}}</span>
</div>
<div>
<span class="comment">{{comment}}</span>
</div>
{{/users}}
</script>
<script src="./js/app.js"></script>
app.js
$("#btn-add").click(() => {
$.get("http://myapis.com/api/users", (users) => {
// *LOC
// I want to set the #my-template users variable to the returned the users api response
}
});
What I'm trying/thinking that at LOC, someway access the #my-template contained users & update its value to users api response (which is an array of users object).*
Thanks!