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

329
Views
¿Cómo agrego código HTML de una página HTML a otra usando Javascript?

Estoy creando una página de "Carrito" y necesito enviar los datos del artículo usando el botón "Agregar al carrito". Esta es la función en Javascript.

 function addProductToCart(title, priceTag, productImage) { var cartShopBox = document.createElement('div') cartShopBox.classList.add('sm-product') var cartItems = document.getElementsByClassName('cartContainer')[0]; var cartItemsNames = document.getElementsByClassName('sm-product-title'); for (var i = 0; i < cartItemsNames.length; i++) { if (cartItemsNames[i].innerText == title) { alert('you already have this in your cart!'); return; } } var cartBoxContent = ` <img src="${productImage}" class="sm-product-img" alt="" /> <div class="sm-text"> <p class="sm-product-title"> ${title} </p> </div> <div class=”prices”> <div class="sm-price">${priceTag}</div> </div> <i class="delete">Remove</i> `; cartShopBox.innerHTML = cartBoxContent; cartItems.append(cartShopBox); cartShopBox.getElementsByClassName('delete')[0].addEventListener('click', removeCartItem); }

Ahora, esto me da un "Error de tipo no detectado: no se pueden leer las propiedades de undefined (leyendo 'agregar'). Este código javascript se encuentra en el archivo productdetails.html y el archivo cart.html, pero no me permite agregar el título , imagen y precio al carrito html.

about 4 years ago · Juan Pablo Isaza
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!