JSFiddle - React, Tailwind, and code Playground

by tomprogramming

HTML

<div id="element">This is my contents before</div>
<button id="b">Replace</button>

CSS

.styledDiv {
 background:#ff0000;
width:200px;
 height:200px;   
}

JavaScript

$("#b").click(function(){
  var frag = document.createDocumentFragment();
    var div = document.createElement("div");
    div.className = "styledDiv";
    frag.appendChild(div);
    
    var element = document.getElementById("element");
    element.parentNode.replaceChild(frag, element);
})