JSFiddle - React, Tailwind, and code Playground
by Scott Kaye
HTML
<div>Don't hide me 1</div>
<div id="hide">Hide me!</div>
<div>Don't hide me 2</div>
JavaScript
function hide(el) {
let base = document.createElement("hidden-element");
base.attachShadow({ mode: "closed" });
el.parentNode.insertBefore(base, el);
base.appendChild(el);
}
function show(el) {
el.parentNode.replaceWith(el);
}
let el = document.querySelector("#hide"),
i = 0;
setInterval(() => {
(++i % 2) ? hide(el) : show(el);
}, 500);