How can I get HTML elements by class in JavaScript?

后端 未结 5 1471
渐次进展
渐次进展 2021-01-22 03:15

I\'m trying to manipulate the HTML through getElementsByClass() but for some reason it doesn\'t work. When I use document.getElementByID() it works? Wh

5条回答
  •  长情又很酷
    2021-01-22 03:43

    It returns an array so set the first element of the array's innerHTML

    document.getElementsByClassName('boldStuff')[0].innerHTML = 'Fred Flinstone';
    

提交回复
热议问题