Create a DOM document from string, without JQuery

后端 未结 9 481
梦如初夏
梦如初夏 2020-12-05 14:12

We\'re looking for ways to create a DOM document in javascript from a string, but without using Jquery. Is there a way to do so? [I would assume so, since J

9条回答
  •  眼角桃花
    2020-12-05 14:42

    I was able to do this by writing the html string on an iframe

    const html = `
    
    
      
      
      
      Document
    
    
    
    
    `
    
    const iframe = document.createElement('iframe')
    iframe.contentDocument.open()
    iframe.contentDocument.write(html)
    iframe.contentDocument.close()
    iframe.addEventListener('load', () => {
      myDocumentObject = iframe.contentDocument
    })
    

提交回复
热议问题