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

154
Views
el boton de agregar al carrito no responde

mi boton de agregar al carrito no responde Apliqué javascript en mi botón Agregar al carrito. En el botón del carrito, asigné un atributo, es decir, producto de datos, el valor que es {{product.id}}.

 var updateBtns = document.getElementsByClassName('update-cart') for (var i = 0; i < updateBtns.length; i++) { updateBtns[i].addEventListener('click', function() { var productId = this.dataset.product var action = this.dataset.action console.log('productId:', productId, 'action:', action) }) }
 <div class="card-body"> <h5 class="card-title fw-bold text-uppercase">{{product.name}}</h5> <p class="card-text"> <h4 style="font-size: 1rem; padding: 0.3rem; opacity: 0.8;">$ {{product.price}} </h4> </p> <button data-product={{product.id}} data-action="add" class="btn btn-outline-secondary add-btn update-cart">ADD TO CART</button> </div> </div>

La consola no muestra nada a pesar de que hago clic en el botón Agregar al carrito varias veces

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

En lugar de getElementsByClassName , use querySelectorAll porque @tacoshy indicó que getElementsByClassName devuelve un objeto de la colección HTML, no una matriz. Además, la length devolvería la cantidad de elementos dentro de una matriz pero no un objeto.

 const updateBtns = document.querySelectorAll('.update-cart') updateBtns.forEach((updateBtn) => { updateBtn.addEventListener('click', (event) => { var productId = updateBtn.dataset.product var action = updateBtn.dataset.action console.log('productId:', productId, 'action:', action) }) })
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!