Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!