ram
12/28/2015 5:29:00 PM
bit-naughty@hotmail.com writes:
>From what I know, both innerHTML and appendChild put stuff
>INTO the browser's current page - but if I appendChild(), is
>that *visible* straightaway? Or does it get put into the DOM
>tree, but is not *shown* straightaway...? Can anyone please
>explain?
The results of both »innerHTML« and »appendChild«
/are/ shown straight away.
You can create a subtree off-screen first and
then eventually insert it into the DOM, to probably
make the process faster.
That's why in a recent post, I
let e = document.createElement( 'strong' );
let t = document.createTextNode( object[ 0 ] );
e.appendChild( t );
document.getElementById( 'id201512271754350100' ).
appendChild( e );
instead of
let e = document.createElement( 'strong' );
document.getElementById( 'id201512271754350100' ).
appendChild( e );
let t = document.createTextNode( object[ 0 ] );
e.appendChild( t );
, still »document.createElement« communicates with
the DOM.
. You can use »createDocumentFragment« to, uh, create a
document fragment, which exists offscreen, then use
»appendChild« to append entries to it quickly, and then
- when it's done - insert the whole DocumentFragment with a
single access to the displayed document's DOM.
(You can't use »innerHTML« directly on the fragment though.)
Or, try whether it's faster to create the new subtree as
an HTML string offscreen and then use »innerHTML« to insert
it all with one or two DOM accesses.