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

108
Vistas
jQuery function is returning more events for a Modal click

I have a website where there are three different modal buttons and I wrote a variable to get the values in a data layer which is working good but when I first click on the button I get 2 events and it starts doubling up for each click afterwards.

Here is my code

function() {
  
    if ({{Click Text}} == 'STUDY DESIGN'){
  
      $(this).each(function() {
      $(this).on("click", function(){
           var imageText = $({{Click Element}}).closest('.d-md-flex').find('.image-wrapper img.image__desktop').attr("alt");
         window.dataLayer = window.dataLayer || [];
         window.dataLayer.push({
         'event': 'studyDesignInteraction',
         'action': imageText
        });
      });
  });
       return true;
     }
  }

GTM Assistant

The first click comes back with two events and it keeps doubling up after each event. How can I only apply to one click?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

$(this) in your code is window

$(this).each(function() { console.log(Object.keys(this)[0])
  $(this).on("click", function() { console.log(Object.keys(this)[0])
    var imageText = $('img').closest('.d-md-flex').find('.image-wrapper img.image__desktop').attr("alt");
    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({
      'event': 'studyDesignInteraction',
      'action': imageText
    });
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="x" class="d-md-flex">
  <div class="image-wrapper">
    <img class="image__desktop" />
  </div>
</div>

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