Home > Net >  Delete all div classes with Javascript
Delete all div classes with Javascript

Time:01-05

I have a question about to remove whole classes below here like whole classes inside lists class including buttons. But it doesn't work tho.

I tried with the other simple codes, but it works as well. I wonder if is there any way to solve this issue. Thank you!

const test2 = document.getElementById("list-id");
test2.classList.remove("lists");

    
    <div  div id="list-id">

        <div  div id="board-id">
            <div ></div>
            <div >Promo Code</div>
            <div  div id="box-1"><button id="1" onclick="deleteBox(this.id)">X</button></div>
            <div  div id="box-2"><button id="2" onclick="deleteBox(this.id)">X</button></div>
            <div  div id="box-3"><button id="3" onclick="deleteBox(this.id)">X</button></div>
            <div  div id="box-4"><button id="4" onclick="deleteBox(this.id)">X</button></div>
            <div  div id="box-5"><button id="5" onclick="deleteBox(this.id)">X</button></div>
            <div  div id="box-6"><button id="6" onclick="deleteBox(this.id)">X</button></div>
            <div ></div>
        </div>

        <div  div id="product-list">
            <h2>Product List</h2>
            <div  div id="1" draggable="true"><button id="1" onclick="deleteProduct(this.id)">X</button></div>
            <div  div id="2" draggable="true"><button id="2" onclick="deleteProduct(this.id)">X</button></div>
            <div  div id="3" draggable="true"><button id="3" onclick="deleteProduct(this.id)">X</button></div>
            <div  div id="4" draggable="true"><button id="4" onclick="deleteProduct(this.id)">X</button></div>
            <div  div id="5" draggable="true"><button id="5" onclick="deleteProduct(this.id)">X</button></div>
            <div  div id="6" draggable="true"><button id="6" onclick="deleteProduct(this.id)">X</button></div>
        </div>
    </div>
 

CodePudding user response:

try this:

  let divs = Array.from(document.getElementsByTagName("div"));
  for (let div of divs) {
    div.className = "";
  }

})

CodePudding user response:

To remove the visible class from the div element, you use the following code: const div = document.querySelector ('div'); div.classList.remove ('info'); Code language: JavaScript (javascript) The remove () method also allows you to remove multiple classes at once, like this:

If you want to remove classes from div you can use javascript for that. just use query selector . for example (const removeclass=document.querySelector('list'); removeclass.classList.remove('list'));

if you want to remove all the class from list you can you this

  •  Tags:  
  • Related