This article was translated from: How to remove all CSS classes using jQuery / JavaScript?
Instead of individually calling $("#item").removeClass()
for every single class an element might have, is there a single function which can be called which removes all CSS classes from the given element? Instead of individually calling for each element that the element may have $("#item").removeClass()
, is there one that can be called Function to remove all CSS classes from a given element?
Both jQuery and raw JavaScript will work. Both jQuery and raw JavaScript will work .
#1st Floor
Reference: https://stackoom.com/question/5yhZ/ How to use jQuery-JavaScript to delete all CSS classes
#2nd Floor
Of course. Of course.
$('#item')[0].className = '';
// or
document.getElementById('item').className = '';
#3rd floor
The SET at The the Just className
attribute of DOM Element at The Real to ''
(Nothing). Just real DOM element className
attribute is set to ''
(no).
$('#item')[0].className = ''; // the real DOM element is at [0]
Edit: Other people have have of Said that the Just Calling removeClass
Works - the I Tested the this with Google JQuery at The Playground: http://savedbythegoog.appspot.com/?id=ag5zYXZlZGJ5dGhlZ29vZ3ISCxIJU2F2ZWRDb2RlGIS61gEM ... and IT Works. Edit: Other people say just call removeClass
work - I tested this with Google JQuery Playground: http : removeClass
... it works. So you can also do it this way: So you can also do it this way :
$("#item").removeClass();
#4th floor
$("#item").removeClass();
Calling removeClass
with NO the Remove All of the Parameters by Will at The Item's classes. Call without parameters removeClass
will delete all entries of the class.
CAN Also use by You (But not Necessarily IS Recommended, at The correct Way IS at The One above): You can also use (but not necessarily recommended, the correct method is the method 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: If you didn't have jQuery, then this would be your only option :
document.getElementById('item').className = '';
#5th Floor
Hang on, doesn't removeClass () default to removing all classes if nothing specific is specified? If no specific content is specified , please hang, delete all classes by default without deleting Class () So so
$("#item").removeClass();
will do it on its own ... will do it on its own ...
#6th floor
The shortest way
$('#item').removeAttr('class').attr('class', '');