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

125
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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