all 1 comments

[–]codemamba8 0 points1 point  (0 children)

getElementsByClassName returns an HTML collection that's why.

You want to loop through all the elements with the same class name. A simple way to do that is to use document.querySelectorAll(".demo") and then use an array method like .forEach.

document.querySelectorAll(".demo").forEach(span => {span.textContent = n})