title: onfocusout event removes my button which cannot execute its code, because the focus removed when I click it
body: <p>I am trying to implement a text field with dropdown search. The drop down items are buttons inside a div which has <code>display: none</code> CSS property. When I click it, The text field should change its content to the content of the button.</p>
  <p>The problem is that the dropdown should disappear when the focus is removed from text field. When I click an item of dropdown, the focus is removed, the button disappears and its <code>onclick</code> doesn't get executed. Is it possible to execute button code which selects name before executing the code which removes this button?</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function showNames() {
    document.getElementById("dropdown_names").style.display = 'block'
  }
  
  function hideNames() {
    document.getElementById("dropdown_names").style.display = 'none'
  }
  
  function selectName(name) {
    document.getElementById("name_inp").value = name
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>#resident_name_inp:focus {
    outline: 3px solid #ddd;
  }
  
  .dd {
    position: relative;
    display: inline-block;
  }
  
  .dd-content {
    display: none;
    position: absolute;
    background-color: #f6f6f6;
    overflow: auto;
    width: 100%;
    border: 1px solid #ddd;
    z-index: 1;
  }
  
  .dd-content button {
    background-color: #ffffff;
    width: 100%;
    padding-left: 4px;
    border: none;
    display: block;
  }
  
  .dd-content button:hover {
    background-color: #ddd;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="dd"&gt;
    &lt;input
    id="name_inp"
    type="text"
    placeholder="Search Names..."
    onfocus="showNames()"
    onfocusout="hideNames()"&gt;
    &lt;div id="dropdown_names" class="dd-content"&gt;
      &lt;button type="button" onclick="selectName('alex')"&gt;alex&lt;/button&gt;
      &lt;button type="button" onclick="selectName('jake')"&gt;jake&lt;/button&gt;
      &lt;button type="button" onclick="selecttName('evgen')"&gt;evgen&lt;/button&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>