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

124
Vistas
Button Text not updating within eventListener

Button text is not updating when the event is triggered. This is a submit event but I've also tried a click event. I've also tested the code outside of the event listener and it works correctly. So the problem seems to be within the event listener. Here is the code:

let addToCartForms = document.querySelectorAll(".bundle-builder--add-to-bundle-form");
    addToCartForms.forEach((el)=>{
        let btn = el.querySelector('.add-to-cart');
        let btnText = btn.innerText;
        
        el.addEventListener("submit",(e)=>{
            btn.innerText = "added"
        });
    })
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Both click and submit work. Maybe the form is submitted so you can't see the effect?

let addToCartForms = document.querySelectorAll(".bundle-builder--add-to-bundle-form");
addToCartForms.forEach((el) => {
  let btn = el.querySelector('.add-to-cart');
  let btnText = btn.innerText;

  el.addEventListener("submit", (e) => {
    btn.innerText = "added"
  });
})
<form class="bundle-builder--add-to-bundle-form">

  <button class="add-to-cart">click</button>

</form>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Maybe this jQuery solution could work.

$('body').on('submit', '.bundle-builder--add-to-bundle-form .add-to-cart', function(e){ 
  (e).preventDefault();
  (this).text('added');
   setTimeout(function() {
  (this).submit()},500)
})

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