3 ms·
I'm not terribly plugged in to the front-end developer community, so don't take this as authoritative, but my preferred (and more reliable) method of handling s
by bmelton 15y ago
I'm not terribly plugged in to the front-end developer community, so don't take this as authoritative, but my preferred (and more reliable) method of handling server input is generally to append new elements to existing, 'container' elements already present on the DOM.
In context, I might have a 'tweets' div on the page that is empty on page load, but which will be populated by appending new div or li elements to.
- chc 15y agoBut 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).
- deleted 15y ago[deleted]
- deleted 15y ago[deleted]
- deleted 15y ago[deleted]