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

180
Visualizações
product:567 Uncaught TypeError: Cannot read properties of undefined (reading 'getElementsByClassName')

Please someone help me out with this

function updatetotal(){
   var cartContent = document.getElementsByClassName('cart-content')[0];   
   console.log(cartContent);

Whenever i run this function via another function given below cart-content class is undefined

function addCartClicked(event){
   var button = event.target
   var shopProducts = button.parentElement.parentElement
   var title = shopProducts.getElementsByClassName('product-title')[0].innerText;
   var price = shopProducts.getElementsByClassName('price')[0].innerText;
   var productImg = shopProducts.getElementsByClassName('product-img')[0].src;
   console.log(title,price,productImg);
   updatetotal();    }

the second function uses classes from diffrent html file and the first one uses classes from diffrent one and both of them have the same js file all functions are working independently but i cant make them work combined.

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