innerHTML inserts only [object HTMLDivElement]

前端 未结 3 454
野的像风
野的像风 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 );
    
    0 讨论(0)
  • 2021-01-17 17:40

    You should use the appendChild method.

    box2.appendChild(box1);
    
    0 讨论(0)
  • 2021-01-17 17:47

    This should work:

    box2.appendChild(box1);
    
    0 讨论(0)
提交回复
热议问题