EN
JavaScript - remove all classList items
0
points
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>