Hello everyone, how are you? I need help with an c...
# ask-questions
d
Hello everyone, how are you? I need help with an click event... I included an HTML modal and need to control its closing and save a variable on localstorage so it doesn't show again after user interaction. I created the code and tested on Codepen and works fine, but when I try on growthbook nothing happens... any ideas? Here is the code:
Copy code
document.addEventListener("DOMContentLoaded", function () {
  // Verifica se a modal já foi exibida
  if (!localStorage.getItem("paymentModalShown")) {
    showModal();
  }

  // Função para exibir a modal
  function showModal() {
    const modal = document.getElementById("paymentModal");
    modal.style.display = "flex";
    localStorage.setItem("paymentModalShown", "true"); // Salva no localStorage
  }

  // Fecha a modal quando o "X" é clicado ou quando a área fora da modal é clicada
  const closeButton = document.querySelector(".close-btn");
  const modal = document.getElementById("paymentModal");

  closeButton.addEventListener("click", closeModal);
  modal.addEventListener("click", function (event) {
    if (event.target === modal) {
      closeModal();
    }
  });

  // Função para fechar a modal
  function closeModal() {
    const modal = document.getElementById("paymentModal");
    localStorage.setItem("paymentModalShown", "true"); // Salva no localStorage
    modal.style.display = "none";
  }
});
f
How is this integrating with GrowthBook?
you're loading this JS via GrowthBook?
d
Yes, I put them on visual editor on the JS tab
f
ah, well, you're waiting for the "DOMContentLoaded" event, which probably already happened
just fire the function