How to hide element when focus is lost?

There is a autocomplete script in pure js. Everything works fine, but there is a caveat - the list box is created using the li element, which, in the absence of pressing (select) remains on the screen. As the simplest way to make it hide when losing focus - switch to another element? You can even timeout. Below is part of code that creates the list box. = "none";

 var list = JSON.parse(jsonStr);

 var ul = document.createElement("ul");

 for (var i = 0; i < list.length; i++ ) {
 var li = document.createElement("li");
 li.dataset.value = list[i]["value"];
 li.innerHTML = list[i]["caption"];
 container.replaceChild(ul, container.firstChild); = "block";
March 12th 20 at 08:05
2 answers
March 12th 20 at 08:07
The simplest way to hang a mouseup on the document.
If we are talking about tabfocus, then you need to look in the direction of the events focus and blur.
You can read here:события-foc...
March 12th 20 at 08:09
While using querySelectorAll() select all li and choked. It turned out that after 5 seconds everything just turns off. The question is not closed, but the cover turned out, at least on the timeout.

Find more questions by tags JavaScriptCSS