How to remove all CSS classes using jQuery/JavaScript?
$("#item").removeClass();
Calling removeClass
with no parameters will remove all of the item's classes.
You can also use (but is not necessarily recommended, the correct way is the one above):
$("#item").removeAttr('class');
$("#item").attr('class', '');
$('#item')[0].className = '';
If you didn't have jQuery, then this would be pretty much your only option:
document.getElementById('item').className = '';
Hang on, doesn't removeClass() default to removing all classes if nothing specific is specified? So
$("#item").removeClass();
will do it on its own...
Just set the className
attribute of the real DOM element to ''
(nothing).
$('#item')[0].className = ''; // the real DOM element is at [0]
Edit: Other people have said that just calling removeClass
works - I tested this with the Google JQuery Playground: http://savedbythegoog.appspot.com/?id=ag5zYXZlZGJ5dGhlZ29vZ3ISCxIJU2F2ZWRDb2RlGIS61gEM ... and it works. So you can also do it this way:
$("#item").removeClass();