title: Creating Multiple Modals on a Single Page
body: <p>I'm having some issues creating multiple modals on a single webpage following the sample code from w3schools.com. The code in question that I am using is this one: <a href="http://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_modal2" rel="noreferrer">http://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_modal2</a></p>
  
  <p>I found a similar topic on the problem however after trying that solution in jsfiddle I still came up with no result, does anyone have any ideas?</p>
  
  <p>Previous Topic:
  <a href="https://stackoverflow.com/questions/37402241/support-for-multiple-modal-single-page">Support for Multiple Modal Single Page</a></p>
  
  <p><a href="https://jsfiddle.net/oa1dr3q6/" rel="noreferrer">https://jsfiddle.net/oa1dr3q6/</a></p>
  
  <pre><code>&lt;h2&gt;1st Modal&lt;/h2&gt;
  
  &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;div class="modal-header"&gt;
  &lt;span class="close"&gt;×&lt;/span&gt;
  &lt;h2&gt;Modal Header&lt;/h2&gt;
  &lt;/div&gt;
  &lt;div class="modal-body"&gt;
  &lt;p&gt;Some text in the Modal Body&lt;/p&gt;
  &lt;p&gt;Some other text...&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class="modal-footer"&gt;
  &lt;h3&gt;Modal Footer&lt;/h3&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;h2&gt;2nd Modal&lt;/h2&gt;
  
  &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;div class="modal-header"&gt;
  &lt;span class="close"&gt;×&lt;/span&gt;
  &lt;h2&gt;Modal Header&lt;/h2&gt;
  &lt;/div&gt;
  &lt;div class="modal-body"&gt;
  &lt;p&gt;Some text in the Modal Body&lt;/p&gt;
  &lt;p&gt;Some other text...&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class="modal-footer"&gt;
  &lt;h3&gt;Modal Footer&lt;/h3&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>
     </p>
  
  <p>Script:</p>
  
  <pre><code>// Get the modal
  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 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>