ARTICLE AD BOX
Learning JS here.
I have this function (Vanilla JS) which allows to access directly the opened modal when typing the url (when typing site.com/#modal-faqs it just shows already opened on the browser).
But it does not close when clicking on the x icon or outside on the modal. How can I achieve this please?
I hope I am clear. Thank you
<section id="faqs"> <div class="section-content"> <div class="container"> <div class="modal" id="modal-faqs"> <div class="modal-content" id="faqs"> <span class="modal-close">×</span> <div class="container"> <div id="centered-txt"> <h1>Title</h1> </div> <div class="so-accordion-wrapper"> Content </div> </div> </div> </div> </div> </div> </section> <script> document.addEventListener("DOMContentLoaded", function() { if (window.location.hash === '#modal-faqs') { document.getElementById('modal-faqs').style.display = 'block'; } }); </script>