Skip to main content

Shadow Dom

window.onload = function () {
let oBody = document.querySelector("body");
let oDiv = document.createElement("div");
oDiv.innerHTML =
"<style>div{height: 200px;width: 200px;background: red;}</style><div>hello</div>";

const { innerHTML } = oDiv;
oDiv.innerHTML = "";
const shadow = oDiv.attachShadow({ mode: "closed" });
shadow.innerHTML = innerHTML;

console.log(shadow);
oBody.appendChild(oDiv);
};