JSFiddle - React, Tailwind, and code Playground

by flyingbee2012

HTML

<html>

  <body>
    <style>
      div {
        color: red;
      }

    </style>
    <script>
function myFunction() {
  const targetWindow = window.open();
  const mydiv = document.createElement('div');
  mydiv.innerHTML = 'my div';
  targetWindow.document.body.appendChild(mydiv);
  
  const styles = document.getElementsByTagName('style');
  const styleClone = styles[1].cloneNode(true);
  
  targetWindow.document.head.appendChild(styleClone);
  
}
</script>
    <div>abc</div>
    <button onclick="myFunction()">Try it</button>
  </body>

</html>