JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<button id="search" onclick="search()" value="Send">Search</button>
</div>
<div id="ex"></div>
JavaScript
function clearResult() {
if (document.getElementById("result") != null) {
alert("remove #result");
$("#result").remove();
if (document.getElementById("result") != null) {
alert("#result still exists");
}
}
alert("Exiting clearResult");
}
function search() {
clearResult();
if (document.getElementById("result") == null) {
alert("add #result");
$('<table id="result"><tr><td>I am a table</td></tr></table>').appendTo('#ex');
}
}