How to remove all classes from an element using jQuery?

5

Instead of removing all classes individually using the remove class: $ ("# div"). removeClass ('class')

For each class an element can have, is there any function that can be called and remove all classes in an element?

I need this in jQuery or Javascript.

    
asked by anonymous 13.12.2017 / 16:34

2 answers

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

Calling removeClass without 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 did not have jQuery, then this would be pretty much your only option:

document.getElementById('div').className = '';
    
13.12.2017 / 16:37
8

Just use the removeClass method with no parameters:

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

Documentation

    
13.12.2017 / 16:37