How can I get HTML elements by class in JavaScript?

后端 未结 5 1412
渐次进展
渐次进展 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:31

    The correct method to call is getElementsByClassName(), and it will give you an array of elements.

    document.getElementsByClassName('boldStuff')
    

    Anyway this is not compatible with older IE version. Check the compatibility here.

提交回复
热议问题