JSFiddle - React, Tailwind, and code Playground

HTML

Content div in green box *may* transfer to red box. Wait for 3 seconds.

<div id="main-area" style="background-color:red">
</div>

<div id="temp-area" style="background-color:green">
    above
    <div id="content">
        <script id="script">
            document.write('Lorem Ipsum Dolor...');
        </script>
    </div>
    below
<div>

JavaScript

setTimeout(function () {
var target = jQuery('#main-area').get(0);
var content = jQuery('#content').get(0);
var script = jQuery('#script').get(0);

//choose one of these 3 methods

// will NOT execute script, because content NOT a <script> tag
target.appendChild(content);

// WILL execute script, because jQuery handles it
// and you will be left with OVERWRITTEN document with just 'Lorem Ipsum Dolor...' text.
//$(target).append(content);

// will NOT execute script
//target.appendChild(script);

// WILL execute the script
var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
script.innerHTML = "alert(0);"
target.appendChild(script);


console.log("done");
}, 3000);