I'm adding textnodes to a documentFragment like this:
var foo = document.createDocumentFragment();
var someText = "Hello World";
foo.appendChild(document.createTextNode(someText));
This works fine, but sometimes I'm being passed "text" which includes inline links like this:
var someOtherText = "Hello <a href='www.world.com'>World</a>";
Which in my handler is converted to hardcoded text instead of a link.
Question:
How do I append an HTML string like the above into a documentFragment? If I'm not using textNodes
can this be done using appendChild
?
<a href='http://stackoverflow.com/'>Stack overflow</a>
but that is still a string. Proof:var a=document.createElement('div'); a.innerHTML = "<a href='http://stackoverflow.com/'>Stack overflow</a>"; console.log('The types are: %s %s', typeof a.innerHTML, typeof a.outerHTML);
. What are the types? string and string. – Oolite