I would like to convert the following string to DOM structure.
text node <div>div node</div>text node<p>paraph node</p> text node
One approach is,
mydiv = document.createElement('div');
mydiv.innerHTML = 'text node <div>div node</div>text node<p>paraph node</p> text node';
In this approach, the DOM structure is wrapped by another div, which is not i wanted.
After do searching and reading, I found document.createDocumentFragment()
is the best way, because when append a fragment
to node, it just append fragment's childNodes
, not fragment itself
unfortunately, innerHTML
method is not available in a fragment
.
what should i do? thanks