问题
I can't understand why getElementsByClassName isn't working here.
n = new Date();
y = n.getFullYear();
document.getElementByClassName("date").innerHTML = y;
<span class="date"></span> CompanyName
回答1:
- The function name is
getElementsByClassName
, notgetElementByClassName
getElementsByClassName
returns an array-like object of elements, not the one of elements.
Code should look like this:
n = new Date();
y = n.getFullYear();
document.getElementsByClassName("date")[0].innerHTML = y;
<span class="date"></span> CompanyName
来源:https://stackoverflow.com/questions/56534225/why-isnt-getelementsbyclassname-working