Create node from markup string

前端 未结 3 493
心在旅途
心在旅途 2021-01-12 22:30

Is there a way to convert markup string to node object in JavaScript? Actually I am looking for the subsitute for:

document.getElementById(\"divOne\").innerH         


        
3条回答
  •  一个人的身影
    2021-01-12 23:00

    function htmlMarkupToNode(html){
        let template = document.createElement("template");        
        template.innerHTML = html ;
        let node = template.content.cloneNode(true) ;        
        return node ;   
    }
    
    document.getElementById("divOne").appendChild(htmlMarkupToNode("
    "));

提交回复
热议问题