JSFiddle - React, Tailwind, and code Playground
HTML
<button>toggle</button>
<div id="test">
</div>
CSS
#box {
height:20px;
width:20px;
background:#000;
margin-left:30px;
}
JavaScript
var iff = 0;
$("button").click(function() {
alert($("#box").length);
if (iff == 0) {
$("#test").html("<div id='box'></div>");
iff = 1;
} else {
$("#box").remove();
iff = 0;
}
});