Appending Html String to the Dom
How to Append a Html String Such as Var Str = 'Just Some Text Here'; to the with the Id Test? (Btw Div. innerHTML += Str; Is Not Acceptable.) 0 10 Answers Use...
How to append a HTML string such as
var str = '<p>Just some <span>text</span> here</p>';
to the <div> with the id test?
(Btw div.innerHTML += str; is not acceptable.)
10 Answers
Use insertAdjacentHTML which is supported in all current browsers:
div.insertAdjacentHTML( 'beforeend', str );
The position parameter beforeend will add inside the element, after its last child.
Live demo:
Must Read
Performance
AppendChild (E) is more than 2x faster than other solutions on chrome and safari, insertAdjacentHTML(F) is fastest on firefox. The innerHTML= (B) (do not confuse with += (A)) is second fast solution on all browsers and it is much more handy than E and F.