2 ms·
But how are you doing that if the server sends back HTML? Like, say you ask for a tweet, and the server sends back the following: <div class="tweet"><div cla
by chc 15y ago
But how are you doing that if the server sends back HTML? Like, say you ask for a tweet, and the server sends back the following:
<div class="tweet"><div class="header"><div class="username">rihanna</div><div class="retweet"><img src="retweet.jpg" alt="retweet"></div><div class="tweet-body">Check out my new tattoo of a woman getting a recursive tattoo!</div></div>
You can't send that to document.createElement. Your only options AFAIK are innerHTML and writing your own DOM parser to build up a tree and use the DOM API to create the elements one by one (which will be OMGslow).
And of course appending a new element doesn't make a lot of sense if your changes are transformative rather than additive (e.g. collaborative editing).