How to get class name through JavaScript

前端 未结 4 1001
[愿得一人]
[愿得一人] 2020-12-21 00:35

How do I get the class name through JavaScript given no id with this span.

Like:

I want to

4条回答
  •  失恋的感觉
    2020-12-21 01:11

    You can use document.getElementsByClassName('xyz'). Note: it returns an array a NodeList (thanks to @IAbstractDownvoteFactory) since there can be multiple elements with the same class.

    var spans = document.getElementByClassName('xyz');
    var i;
    for(i=0; i

提交回复
热议问题