JQuery - delete multiple classes

Is there a more efficient way to remove several unnecessary classes from dom elements at once?

Js

$('.one').removeClass('one'); $('.two').removeClass('two'); $('.three').removeClass('three'); 
+8
jquery
source share
2 answers

Selecting more than one item separated by a comma; Removing more than one class from an item separated by a space

 $('.one, .two, .three').removeClass('one two three'); 

Demo

+16
source share

If you want to remove multiple classes from one element , then separate the classes with a space.

 http://api.jquery.com/removeClass/ One or more space-separated classes to be removed from the class attribute of each matched element. 

If you want to remove different classes from different elements , I think, then it would be better to make an array and delete classes, iterate over it.

+1
source share

All Articles