Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda