How can I remove all CSS classes using jQuery/JavaScript?

Solution 1:

$("#item").removeClass();

Calling removeClass with no parameters will remove all of the item's classes.


You can also use (but it 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 = '';

Solution 2:

Hang on, doesn't removeClass() default to removing all classes if nothing specific is specified? So

$("#item").removeClass();

will do it on its own...