I have a template file that I get from the server using ajax. The file is something like that
<!DOCTYPE HTML>
<html>
<body>
<script id="temp_1" type="x-tmpl-mustache">
Hello {{ name }}!
</script>
<script id="temp_2" type="x-tmpl-mustache">
Hello {{ name }}!
</script>
</body>
</html>
How can I access the innerHTML of temp_1 and temp_2 without inserting the file into the page? Basically, this is what I'm trying to achieve.
var templates;
$.get( "templates.html", function( data ) {
templates = data;
});
// Access the dom element like this
// templates.document.querySelector('#temp_1').innerHTML > Hello {{ name }}!
I've said it in the comment but gonna say it again
I've fixed the problem with using DOMParser which you can see here. @23528 marked my question as duplication and linked to another question which has nothing to do with my question. So if you are having the same problem, use DOMParser.