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

164
Vistas
How do I target dynamic buttons created with different values jQuery

I have a button where when it's clicked I want the text to change to something else now the problem is that the button has the same class and everything as the other buttons on the page which will be generated dynamically since it's inside a foreach

How can I target only the button I click to change the text I have different values for each button can I use that?

<label class="more-information" value="{I call a data id with php}">
 <span class="more-info-text">Default text</span>
</label>
$('.more-information').on('click', function () {
      $(this).toggleClass('active');
      $(this).hasClass('active') ? $(".more-info-text").text('Default Text') : $(".more-info-text").text('Changed Text');

    });

This is what I'm currently using and it changes the text for all the buttons only when one button is clicked

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

0

$('.more-information').on('click', function () {
      $(this).toggleClass('active');
      $(this).hasClass('active') ? $(this).find(".more-info-text").text('Default Text') : $(this).find(".more-info-text").text('Changed Text');

});

$(this).find(".more-info-text") will find the exact label for you on the click.

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