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

176
Views
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
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!