JSFiddle - React, Tailwind, and code Playground

by JeffC

HTML

<p id="test">test</p>

JavaScript

window.setTimeout(function () {
    alert(CheckExists('test1'));
}, 1000);
window.setTimeout(function () {
    InsertElement('test');
}, 2000);
window.setTimeout(function () {
    alert(CheckExists('test1'));
}, 3000);

function InsertElement(id) {
    var e = document.getElementById(id);
    var div = document.createElement("div");
    div.id = "test1";
    div.innerHTML = "test1";
    e.appendChild(div);
}

function CheckExists(id) {
    var e;
    try {
        e = document.getElementById(id);
    } finally {
        if (e === null) {
            return false;
        } else {
            return true;
        }
    }
}