How to remove class attribute from div?

前端 未结 8 887
感情败类
感情败类 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:40

    Try this :

    window.onload = function(){
                var buttonGo = document.getElementsByTagName('button')[0];
                var buttonCom = document.getElementsByTagName('button')[1];
                var box = document.getElementById('box');
                buttonGo.onclick = function(){
                    box.setAttribute('class','move');
                }
                buttonCom.onclick = function(){
                   box.className=''
                }
           }
    

    or double quotes box.className=""

    0 讨论(0)
  • 2021-02-05 13:43

    box.removeAttribute("class") should work.

    0 讨论(0)
提交回复
热议问题