Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
exit popup with Javascript

I'm trying to exit a popup with JS. I've just followed a tutorial but nothing happens on my popup I'm just thinking if this is a class problem maybe I'm pointing to the wrong class but I've tried everything i know my pop-up can't work at this moment but i'm at the beginning of my project

here's the link of the tutorial i've followed : https://www.webtips.dev/how-to-make-an-effective-exit-intent-popup-in-javascript

  const exit = (e) => {
      if (e.target.className === "close") {
        // user click on the close button
        document.querySelector(".modal-body").classList.remove("visible");
      }
    };

    document.querySelector(".modal-body").addEventListener("click", exit);
<div class="bground">
        <div class="content">
          <span class="close"></span>
          <div class="modal-body">
            <form
              name="reserve"
              action="index.html"
              method="get"
              onsubmit="return validate();"
            >
              <div
                class="formData">
                <label>Prénom</label><br>
                <input
                  class="text-control"
                  type="text"
                  id="first"
                  name="first"
                  minlength="2"
                /><br>
                <br>
                <input class="checkbox-input" type="checkbox" id="checkbox2" />
                <label class="checkbox2-label" for="checkbox2">
                  <span class="checkbox-icon"></span>
                  Je Je souhaite être prévenu des prochains évènements.
                </label>
                <br>
              </div>
              <input
                class="btn-submit"
                type="submit"
                class="button"
                value="C'est parti"
              />
            </form>
          </div>
        </div>
      </div>

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I think you have wrong class in eventHandler here:

document.querySelector(".modal-body").addEventListener("click", exit);

should be:

document.querySelector(".close").addEventListener("click", exit);

Check this sandbox: https://codesandbox.io/s/stoic-hellman-3x9y2s?file=/src/index.js

about 4 years ago · Juan Pablo Isaza Relatório

0

The Element with .close is outside the .modal-body when performing the click event, the supplied event object does not contain the class you are looking for. As a starting point to debug, you can just console.log(e); and see whats in that particular object

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda