function displaySproutModal() { var modal_a = document.getElementById("SproutModalMain"); // modal.style.display = "block"; // block displays it. var span = null; var modal = document.getElementById("SproutModalMain_user") if (!modal) { var modal = modal_a.cloneNode(true) modal.id ="SproutModalMain_user" var span = modal.getElementsByClassName("SproutModalClose")[0] document.body.appendChild(modal); } modal.style.display = "block"; // When the user clicks on (x), close the modal span.onclick = function () { modal.style.display = "none"; modal.remove() } // // When the user clicks anywhere outside of the modal, close it window.onclick = function (event) { if (event.target == modal) { modal.style.display = "none"; modal.remove() } } }