Insert HTML with Javascript
how to insert HTML strings into the DOM with straight javascript
by akmiecik
HTML
<div id="box1">
<p>Some example text</p>
</div>
<div id="box2">
<p>Some example text</p>
</div>
<!-- source:
http://coding.smashingmagazine.com/2013/10/06/inside-the-box-with-vanilla-javascript/
//-->
CSS
#test {
height: 30px;
width: 30px;
background: red;
}
JavaScript
var box1 = document.getElementById("box1");
var box2 = document.getElementById("box2");
box1.insertAdjacentHTML('afterend', '<div id="test">');