How to get class name through JavaScript

前端 未结 4 1004
[愿得一人]
[愿得一人] 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条回答
  •  梦毁少年i
    2020-12-21 01:28

    You can use a jquery to solve the same issue.

     var classname = $(this).attr('class'); //here you will get current class name if its with multiple class split it and take first class.
       $("."+classname.split(" ")[0]).css("background-color", "yellow");
    

提交回复
热议问题