I obtain an active copy of an HTML5 <template>
using function importNode()
:
function getTemplate() {
var t = document.getElementById("example");
return document.importNode(t.content,true);
}
After this, I fill the dynamic data,
var t = fillTemplate({
id:"test",
text:"Enter test data"
});
and finally, I append the node into the target container:
var c = document.getElementById("container");
var result = c.appendChild(t);
My problem: the result
node has all its content stripped off: I can't access the component elements of the template in the result node. Actually, the result
node contains no child nodes at all once the appendChild
operation has been performed.
I expect that the return value of appendChild
should point to the node that has been inserted into the container and which is now part of the active document. Any explanation why this is not the case?
Here is the jsfiddle (tested in Chrome 53):