innerHTML inserts only [object HTMLDivElement]

前端 未结 3 456
野的像风
野的像风 2021-01-17 16:43

i want to insert a htmlsnippet into another html-element

i tried it this way

the html

insert this html elemen
3条回答
  •  心在旅途
    2021-01-17 17:40

    innerHTML doesn't insert DOM nodes, just strings.
    Use appendChild instead

    var box1 = document.querySelector(".box1"); 
    var box2 = document.querySelector(".box2");
    
    box2.appendChild( box1 );
    

提交回复
热议问题