Remove all classes except one Remove all classes except one javascript javascript

Remove all classes except one


Instead of doing it in 2 steps, you could just reset the entire value at once with attr by overwriting all of the class values with the class you want:

jQuery('#container div.cleanstate').attr('class', 'cleanstate');

Sample: http://jsfiddle.net/jtmKK/1/


Use attr to directly set the class attribute to the specific value you want:

$('#container div.cleanstate').attr('class','cleanstate');


With plain old JavaScript, not JQuery:

document.getElementById("container").className = "cleanstate";