How to remove class attribute from div?

前端 未结 8 918
感情败类
感情败类 2021-02-05 13:12

I am using JavaScript and I want to add/remove a Class attribute if a button is clicked. I am able to add the class, but I don\'t know how to remove it. how can I do that?

8条回答
  •  一向
    一向 (楼主)
    2021-02-05 13:28

    The nicest way to set classes with Javascript is to use the className property:

    // to add
    box.className = 'move';
    // to remove
    box.className = '';
    

提交回复
热议问题