JSFiddle - React, Tailwind, and code Playground
by Marco
HTML
<input name="" type="button" id="button">
<div id="cBox"></div>
CSS
#cBox{
background-color: #066;
height: 100px;
width: 100px;
}
JavaScript
function closeBox(elem){
elem.parentNode.removeChild(elem);
}
function openBox(el){
var el = document.createElement('div');
el.setAttribute("id", "cBox");
document.body.appendChild(el);
}
var btnPress = document.getElementById('button');
btnPress.onclick = function formConfirm() {
var cBox = document.getElementById('cBox');
if(cBox) {
closeBox(cBox)
console.log("cbox exists, closing ...");
} else {
openBox(cBox);
console.log("cbox does not exist, creating...");
}
};