title: Alert box - How to save close(x) in browser cache
body: <p>Here I have simple alert box:</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-css lang-css prettyprint-override"><code>/* The alert PROMO box */
  .promobox {
    padding: 10px;
    background-color: #415ca2; /* Blue */
    color: white;
    margin-bottom: 7px;
  }
  
  /* The close button */
  .closebtnpr {
    margin-left: 15px;
    color: white;
    font-weight: bold;
    float: right;
    font-size: 18px;
    line-height: 20px;
    cursor: pointer;
    transition: 0.3s;
  }
  
  /* When moving the mouse over the close button */
  .closebtn:hover {
    color: black;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="promobox"&gt;
      &lt;span class="closebtnpr" onclick="this.parentElement.style.display='none';"&gt;×&lt;/span&gt;
      &lt;center&gt;&lt;b&gt;U.S. POLO ASSN. DAY!&lt;/b&gt;&lt;/center&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>When I click on (x) then hide element. But when I refresh page then again is displayed alert box. </p>
  
  <p>How can I remember the choice of closing the alert box until I finish browsing the website?</p>
  
  <p>update2:</p>
  
  <pre><code>sessionStorage.setItem('myCat', 'Tom');
  </code></pre>
  
  <p>The following example autosaves the contents of a text field, and if the browser is accidentally refreshed, restores the text field content so that no writing is lost.</p>
  
  <pre><code>// Get the text field that we're going to track
  let field = document.getElementById("field");
  
  // See if we have an autosave value
  // (this will only happen if the page is accidentally refreshed)
  if (sessionStorage.getItem("autosave")) {
    // Restore the contents of the text field
    field.value = sessionStorage.getItem("autosave");
  }
  
  // Listen for changes in the text field
  field.addEventListener("change", function() {
    // And save the results into the session storage object
    sessionStorage.setItem("autosave", field.value);
  });
  </code></pre>