title: Error with modal and JS - Error Uncaught TypeError: Cannot read property 'classList' of null
body: <p>so i am trying to do this modal however i am getting this error when i try to use the button, i am not sure if the is how it is done as this is my first time using js and i have been following tutorials. Thank you for the help.</p>
  <p>ERROR {
  &quot;message&quot;: &quot;Uncaught TypeError: Cannot read property 'classList' of null&quot;,
  &quot;filename&quot;: &quot;https://stacksnippets.net/js&quot;,
  &quot;lineno&quot;: 67,
  &quot;colno&quot;: 21
  }</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>const open = document.getElementById('open');
  const modal_container = document.getElementById('modal_container');
  const close = document.getElementById('close');
  
  open.addEventListener('click', () =&gt; {
      modal_container.classList.add('show');
  });
  
  close.addEventListener('click', () =&gt; {
      modal_container.classList.remove('show');
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>button {
    background-color: crimson;
    border: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    color: white;
    padding: 20px 30px;
    font-size: 14px;
    border-radius: 5px;
    margin-top: 10px;
  }
  .modal-container {
    background-color: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    opacity: 0;
    pointer-events: none;
    top: 0;
    left: 0;
    height: 100vh;
    width: 100vw;
    z-index: 1;
  }
  .modal-container .show {
    pointer-events: auto;
    opacity: 1;
  }
  .modal {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    background-color: white;
    border-radius: 5px;
    padding: 30px 50px;
    width: 800px;
    max-width: 100%;
    text-align: center;
  }
  .modal h1 {
    margin: 0;
  }
  .modal p {
    opacity: 0.7;
    font-size: 14px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code> &lt;button id="open"&gt;Introduction&lt;/button&gt;
    &lt;div class="modal-container" id="modal-container"&gt;
        &lt;div class="modal"&gt;
            &lt;h1&gt;Introduction&lt;/h1&gt;
            &lt;p&gt;Lorem ipsum dolor, sit amet consectetur adipisicing elit. Dicta pariatur ut, veniam illum nemo repellat explicabo dignissimos ex ipsum aliquid.&lt;/p&gt;
            &lt;button id="close"&gt;Click here to close.&lt;/button&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    </code></pre>
  </div>
  </div>
  </p>