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?
<div>
test
(Btw div.innerHTML += str; is not acceptable.)
div.innerHTML += str;
Use insertAdjacentHTML which is supported in all current browsers:
insertAdjacentHTML
div.insertAdjacentHTML( 'beforeend', str );
The position parameter beforeend will add inside the element, after its last child.
beforeend
Live demo: http://jsfiddle.net/euQ5n/
2.1m questions
2.1m answers
60 comments
57.0k users