title: how to make one close button for all functions? in js
body: <p>help me please check my code</p>
  <p>Get the modal</p>
  <pre><code>var modal;
  var overlay = document.getElementById(&quot;overlay&quot;);
  </code></pre>
  <p>Get the button that opens the modal</p>
  <pre><code>var btn_carapesan = document.getElementById(&quot;btn-carapesan&quot;);
  var btn_ketentuan = document.getElementById(&quot;btn-ketentuan&quot;);
  var btn_jaminan = document.getElementById(&quot;btn-jaminan&quot;);
  var btn_harga = document.getElementById(&quot;btn-harga&quot;);
  </code></pre>
  <p>When the user clicks on the button, open the modal</p>
  <pre><code>btn_carapesan.onclick = function() {
    modal = document.getElementById(&quot;modal-carapesan&quot;);
    modal.style.display = &quot;block&quot;;
    document.getElementById(&quot;overlay&quot;).style.display = &quot;block&quot;;
  }
  
  btn_ketentuan.onclick = function() {
    // var span = document.getElementsByClassName(&quot;close&quot;)[1];
    modal = document.getElementById(&quot;modal-ketentuan&quot;);
    modal.style.display = &quot;block&quot;;
    document.getElementById(&quot;overlay&quot;).style.display = &quot;block&quot;;
  }
  
  btn_jaminan.onclick = function() {
    // span = document.getElementsByClassName(&quot;close&quot;)[2];
    modal = document.getElementById(&quot;modal-jaminan&quot;);
    modal.style.display = &quot;block&quot;;
    document.getElementById(&quot;overlay&quot;).style.display = &quot;block&quot;;
  }
  
  btn_harga.onclick = function() {
    // span = document.getElementsByClassName(&quot;close&quot;)[3];
    modal = document.getElementById(&quot;modal-harga&quot;);
    modal.style.display = &quot;block&quot;;
    document.getElementById(&quot;overlay&quot;).style.display = &quot;block&quot;;
  }
  </code></pre>
  <p>Get the  element that closes the modal</p>
  <pre><code>var span = document.getElementsByClassName('close')[0];
  
  // When the user clicks on &lt;span&gt; (x), close the modal
  span.onclick = function() {
    modal.style.display = &quot;none&quot;;
    document.getElementById(&quot;overlay&quot;).style.display = &quot;none&quot;;
  }
  </code></pre>
  <p>i have one close button for each modal, i can use close modal in first modal but not work in so on modal</p>