What you're passing to function updateValue(span) { span.innerHTML = formatBytes(parseFloat(span.innerHTML)); }
is the span
element, not its content. You're also trying to set textContent
on innerHTML
(which is an HTMLCollection), not on the element you passed (v
). Instead:
size[i]
Or you might use item
rather than parseFloat
.
A couple of side notes:
-
You can use
/
rather than/
. The olditem
function is a bit archaic. -
You never need to call
sizeSpans
on the result of/
, the result of/
is already always a number. -
Strongly recommend naming variables containing lists, arrays, collections, etc. in the plural. E.g.,
size
or similar, notgetElementsByClassName
. -
If you need to support IE8 (hopefully you don't), it doesn't have
querySelectorAll
but it does havevar size = document.querySelectorAll(".size")
which is more general-purpose (accepts any valid CSS selector):textContent
. -
Similarly, if you need to support IE8, be aware it doesn't have
textContent
.