How to Remove a Class from the Body Element Using JavaScript?

Estimated read time 1 min read

To remove a class from the body element using JavaScript, you can use the classList.remove() method:

document.body.classList.remove("className");

Here, document.body refers to the body element, and classList.remove("className") removes the class "className" from it.

Alternatively, you can also use the className property to manipulate the class list:

document.body.className = document.body.className.replace(/\bclassName\b/,'');

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply