Languages
[Edit]
EN

JavaScript - remove all classList items

0 points
Created by:
Lilly-Grace-Greig
571

In this article, we would like to show you how to remove all items from the element's classList using JavaScript.

Practical example

In this example, we remove all the classes from the element by setting element.className to the empty string ('').

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<body>
  <div id="element" class="border shadow">Some content here ...</div>
  <script>

    var element = document.querySelector('#element');

    element.className = ''; // <--- clears classList

    console.log(element.outerHTML);

  </script>
</body>
</html>

References

  1. Element.className - Web APIs | MDN

Alternative titles

  1. JavaScript - remove all class list items
  2. JavaScript - clear classList
  3. JavaScript - clean classList
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join