JSFiddle - React, Tailwind, and code Playground

HTML

<input id="but" type="button" value="pressMe" />
       <div id="window" style="display:none">popup</div>

JavaScript

document.getElementById("but").onclick = function(e) {
    showDropDown(this, e);
};

function showDropDown(element, e) {
    element.onclick = function() {};
    if (e.stopPropagation) 
        e.stopPropagation(); // W3C model
    else 
        e.cancelBubble = true; // IE model
    document.getElementById("window").style.display = "inline-block";
    document.onclick = function(e) 
    {
        var ele = document.elementFromPoint(e.clientX, e.clientY);
        if (ele == element) {
            hideDropDown();
            return;
        }
        do {
            if (ele == document.getElementById("window")) return;
        } while ((ele = ele.parentNode) !== null);
        hideDropDown(element);
    };
}

function hideDropDown(element){
    document.onclick = function() {};
    document.getElementById("window").style.display = "none";
    element.onclick = function(e) {
        showDropDown(this, e);
    };
}