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

330
Vistas
How do I append HTML code from one HTML page to another using Javascript

I am making a "Cart" page, and I need to send the item data using the "Add to Cart" button. This is the function in 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);

       }

Now, this gives me an "Uncaught TypeError: Cannot read properties of undefined (reading 'append'). This javascript code is found in the productdetails.html file and the cart.html file, but it does not allow me to append the title, image, and price to the cart html.

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