Hello!
Please tell me how in JavaScript (without using jQuery and other libraries) to insert such html block:
<div id="id1"> <span class="class1"> Текст1 </span> </div>
Paste to the end of the main block:
<div id="main"> <div id="id2"> <span class="class2"> Текст2 </span> </div> </div>
I try to do this:
var main= document.getElementById("main"); main.appendChild('<div id="id1"><span class="class1"> Текст1 </span> </div>');
But an error occurs. Apparently you need to create a DIV through CreateElement
, setAttribute("id", "id1")
, and then add. <span class="class1"> Текст1 </span>
.InnerHTML
<span class="class1"> Текст1 </span>
through .InnerHTML
. It is somehow difficult. Is it possible to make it easier?
Thank!