title: Having Multiple Modals per page
body: <p>I'm creating a website where the user can click on an image to open a modal with menu items within, while the first modal works fine, subsequent modals do not.</p>
  
  <p>JS Code:</p>
  
  <pre><code>&lt;script&gt;
  // Get the modal
  var modal = document.getElementById('myModal');
  
  // Get the button that opens the modal
  var btn = document.getElementById("myImg");
  
  // 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";
      }
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>HTML where its used:</p>
  
  <pre><code>    &lt;div class="col-md-3"&gt;
          &lt;h2&gt;Starters&lt;/h2&gt;
          &lt;img src="http://foodnetwork.sndimg.com/content/dam/images/food/fullset/2007/2/9/0/ie0102_coleslaw.jpg" height="100%" width="100%" id="myImg"&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;br&gt;
                        &lt;h2&gt;Starters&lt;/h2&gt;
                      &lt;/div&gt;
                      &lt;div class="modal-body"&gt;
                        &lt;p&gt;&lt;b&gt;PRODUCT &lt;span style="display:inline-block; width: 75%;"&gt;&lt;/span&gt; PRICE&lt;/b&gt;&lt;/p&gt;
                        &lt;hr&gt;
                        &lt;p&gt; Humus &lt;span style="display:inline-block; width: 78%;"&gt;&lt;/span&gt;  £3.00&lt;/p&gt;
                        &lt;p&gt; Dolma &lt;span style="display:inline-block; width: 78%;"&gt;&lt;/span&gt;  £3.20&lt;/p&gt;
                        &lt;p&gt; Coleslaw &lt;span style="display:inline-block; width: 77%;"&gt;&lt;/span&gt;  £1.50&lt;/p&gt;
                        &lt;p&gt; Prawn Cocktail &lt;span style="display:inline-block; width: 73.5%;"&gt;&lt;/span&gt;  £4.60&lt;/p&gt;
                      &lt;/div&gt;
  
                    &lt;/div&gt;
  
                  &lt;/div&gt;
  
      &lt;/div&gt;
  
      &lt;div class="col-md-3"&gt;
          &lt;h2&gt;Wraps&lt;/h2&gt;
          &lt;img src="http://harryskebabs.com/images/demo/menu-main/menu-item-large-20.jpg" height="100%" width="100%" id="myImg"&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;br&gt;
                        &lt;h2&gt;Starters&lt;/h2&gt;
                      &lt;/div&gt;
                      &lt;div class="modal-body"&gt;
                        &lt;p&gt;&lt;b&gt;PRODUCT &lt;span style="display:inline-block; width: 75%;"&gt;&lt;/span&gt; PRICE&lt;/b&gt;&lt;/p&gt;
                        &lt;hr&gt;
                        &lt;p&gt; Chicken Wrap &lt;span style="display:inline-block; width: 78%;"&gt;&lt;/span&gt;  £3.00&lt;/p&gt;
                        &lt;p&gt; Doner Wrap &lt;span style="display:inline-block; width: 78%;"&gt;&lt;/span&gt;  £3.20&lt;/p&gt;
                        &lt;p&gt; Shish Wrap &lt;span style="display:inline-block; width: 77%;"&gt;&lt;/span&gt;  £1.50&lt;/p&gt;
                        &lt;p&gt; Kofte Wrap &lt;span style="display:inline-block; width: 73.5%;"&gt;&lt;/span&gt;  £4.60&lt;/p&gt;
                      &lt;/div&gt;
  
                    &lt;/div&gt;
  
                  &lt;/div&gt;
  
      &lt;/div&gt;
  </code></pre>
  
  <p>The first modal box shown will work as expected, while the second will not show at all, i would rather not have to unnecessarily replicate JavaScript if i don't have to, which is why i tired this method. </p>
  
  <p>Very new to JS and modal boxes, so any input would be appreciated, thanks. </p>