Streaming live at 10am (PST)

Custom code for finding sum of CMS items field


I am trying to create a simple function that updates a divs innerHTML based on a sum I am pulling from a CMS collection.

It is currently set up like so:

  const items = document.getElementsByClassName("amount-count");
  let sum = 0;

  for (item of items) {
    sum += parseInt(item.innerHTML);
  const total = document.getElementsByClassName("amount-total");
  total.innerHTML = "$" + sum;

If I console log “total”, I get what I’m looking for. But the page itself is not displaying the information at all.

Here is my site Read-Only:

Look for consumer > dashboard

total is an array in your code.

1 Like

So how do I resolve my issue then?

See accessing array elements on MDN Array - JavaScript | MDN

1 Like

Got it. Thank you for the help!

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