Why isn't getElementsByClassName working?

梦想的初衷 提交于 2021-02-04 21:56:48

问题


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:


  1. The function name is getElementsByClassName, not getElementByClassName
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!