1. Creating DOM-nodes from HTML-text in JavaScript

    To create DOM nodes from a string containing HTML in JavaScript this is what I use:

    let html = '<div><span>Part 1</span><span>the rest of it</span></div>'
    
    let node = document.createRange().createContextualFragment(html).firstChild
    

    Next, the created node can be added to the DOM, for example using element.prepend, element.append or in the way that best fits your situation:

    document.body.prepend(node)
    

    Found this technique here.