When i use document.getElementsByClassName nothing change and i get no errors in the console

   <h5>Grand Total</h5>
                            <div class="ml-auto h5"> <span class="grandtotal">$0.00</span></div>
                        </div>

js

if  (document.readyState == `loading`)
    {document.addEventListener(`DOMContentLoaded`,ready)}
else{ready}
function ready(){const removebutton = document.querySelectorAll(`.remove-pr`);
 console.log(removebutton);
for( let i=0 ; i < removebutton.length; i++){
    const button = removebutton[i]
    button.addEventListener(`click`,function(event){
        var buttonclicked= event.target
        buttonclicked.parentElement.parentElement.parentElement.remove()
    updatecarttotal()})}
}
 
function updatecarttotal() {
    var cartitemcontainer = document.getElementsByClassName(`table`)[0]
     var removebutton = document.querySelectorAll(`.cart-items`)
     var total =0
     for( let i= 0 ; i < removebutton.length; i++){
         var removebutton = removebutton[i]
         var priceelement = removebutton.getElementsByClassName(`price-pr`)[0]
         var quantitylement = removebutton.getElementsByClassName(`cart-quantity-input`)[0]
         
         
         var price =parseFloat(priceelement.innerText.replace(````
   <h5>Grand Total</h5>
                            <div class="ml-auto h5"> <span class="grandtotal">$0.00</span></div>
                        </div>

js

,``))
         var quantity = quantitylement.value
         total = total + (price*quantity)
         
         }
  document.getElementsByClassName("grandtotal").innerText=````
   <h5>Grand Total</h5>
                            <div class="ml-auto h5"> <span class="grandtotal">$0.00</span></div>
                        </div>

js

+total;
    
}

i have a code that waits for js to load its the first bit so if i dont have a mistake in that code i dont think it got to do with the dom. thank you so much ~

I guess in the last line
document.getElementsByClassName(“grandtotal”)
should be
document.getElementsByClassName(“grandtotal”)[0]

try and let me know

thank you so much <3

1 Like

glad I could be of help…

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.