title: How to adapt modal pop up to work inside a loop
body: <p>How can i adapt the below to action multiple times on the same page while using the same class for each? I want to action this within a loop so they can't have different ids or data-values. </p>
  
  <pre><code>var modal = document.getElementById('myModal');
  
  // Get the button that opens the modal
  var btn = document.getElementById("myBtn");
  
  // Get the &lt;span&gt; element that closes the modal
  var span = document.getElementsByClassName("close")[0];
  
  // When the user clicks on the button, open the modal 
  btn.onclick = function () {
      modal.style.display = "block";
  }
  
  // When the user clicks on &lt;span&gt; (x), close the modal
  span.onclick = function () {
      modal.style.display = "none";
  }
  
  // When the user clicks anywhere outside of the modal, close it
  window.onclick = function (event) {
      if (event.target == modal) {
          modal.style.display = "none";
      }
  }
  </code></pre>
  
  <p>HTML</p>
  
  <pre><code>&lt;!-- Trigger/Open The Modal --&gt;
  &lt;button id="myBtn"&gt;Open Modal&lt;/button&gt;
  
  &lt;!-- The Modal --&gt;
  &lt;div id="myModal" class="modal"&gt;
  
  &lt;!-- Modal content --&gt;
  &lt;div class="modal-content"&gt;
  &lt;span class="close"&gt;&amp;times;&lt;/span&gt;
  &lt;p&gt;Some text in the Modal..&lt;/p&gt;
  &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>