I want JavaScript to output a string in every matching location using InnerHTML, but it’s only handling the first one. It works perfectly fine the first encounter, but ignores the others.
I can resolve the matter by doing this:
document.getElementById('num1').innerHTML=num;
document.getElementById('num2').innerHTML=num;
// etc.
But that’s insanely redundant.
Is .getElementById meant to only handle the first matching tag?
Yes, it is supposed to return (at most) just the one element that has the specified id (the exact id, not some prefix or regular expression match).
If you want to match many elements, you should consider giving them a common class.
Or maybe they have a common ancestor and path, so you could select them with something like
(all spans within the element with the id
commonParentId, supported by IE8 and above).