How to remove all Classes from an element using jQuery?

Asked

Viewed 3,969 times

5

Instead of removing all classes individually using remove class:

$("#div").removeClass('classe')

For every class an element may have, there is some function that can be called and remove all classes in an element?

I need this in jQuery or Javascript.

2 answers

9

Just use the method removeClass parameter-less:

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

Documentation

9


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

Call removeClass no parameters will remove all classes from the item.

You can also use (but not necessarily recommended, the correct path is the one above):

$("#div").removeAttr('class');
$("#div").attr('class', '');
$('#div')[0].className = '';

If you didn’t have jQuery, then this would be practically your only option:

document.getElementById('div').className = '';

Browser other questions tagged

You are not signed in. Login or sign up in order to post.