Amra Amra - 1 year ago 93
CSS Question

Remove CSS class from element with JavaScript (no jQuery)

Could anyone let me know how to remove a class on an element using JavaScript only?
Please do not give me an answer with jQuery as I can't use it, and I don't know anything about it.

Answer Source

You could simply set the elements class to nothing.

document.getElementById("whatever").className = "";

or if you wanted to keep a particular class you could just reset the class

document.getElementById("whatever").className = "";
document.getElementById("whatever").className = "classToKeep";


My answer above was incorrect, referencing the answer from @Paul Rouget below, this is the correct answer:


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download