title: error when trying to click on element that was hidden and then made visible again
body: <p>When I click a button I am using axios to send some data to my node.js backend and when the button is clicked I hide it and show a spinner. If something goes wrong, I hide the spinner and show the buttons again. That works fine. But if I click on the button after it is visible again I get an error that says :</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'insertAdjacentHTML' of null
        at renderLoader (26786sdg72635287hd)
        at HTMLAnchorElement.document.querySelector.addEventListener.e</p>
  </blockquote>
  
  <p>HTML: </p>
  
  <pre><code>&lt;div class="spinner"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>JAVASCRIPT</p>
  
  <pre><code>    const renderLoader = parent =&gt; {
          const loader = `
             &lt;div class="loader"&gt;
                  &lt;svg&gt;
                      &lt;use href="/images/icons.svg#icon-cw"&gt;&lt;/use&gt;
                  &lt;/svg&gt;
              &lt;/div&gt;
          `;
          parent.insertAdjacentHTML('afterbegin', loader);
      };
  
      const clearLoader = () =&gt; {
          const loader = document.querySelector('.spinner');
          if (loader) {
              loader.parentElement.removeChild(loader);
          }
      };
  
      document.querySelector('.approve').addEventListener('click', e =&gt; {
          e.preventDefault();
          const csrf = document.querySelector('[name=_csrf]').value;
          const productId = document.querySelector('[name=productId]').value;
          document.querySelector('.approve').style.visibility = 'hidden';
          document.querySelector('.reject').style.visibility = 'hidden';
  
          renderLoader(document.querySelector('.spinner'));
  
  
          axios.post('/account/approve/' + productId, {
              status: 'approved'
          },
              {
                  headers: {
                      'csrf-token': csrf
                  }
  
              })
              .then(response =&gt; {
  
                  const approveBox = document.querySelector('.dashboard-list-box');
                  const successMessage = document.querySelector('.success');
                  approveBox.classList.add('fade-out');
                  successMessage.classList.add('notification');
                  successMessage.innerHTML = response.data.message;
                  clearLoader();
  
              })
              .catch(err =&gt; {
                  clearLoader();
                  document.querySelector('.approve').style.visibility = 'visible';
                  document.querySelector('.reject').style.visibility = 'visible';
              });
      });
  </code></pre>