Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery remove all classes from class

Tags:

jquery

How can I remove all classes from a class but keep the original class?

html

<div class="document-wrapper removeme1 removeme2 removeme3"></div>

jquery

$('.document-wrapper').removeClass();

end with this

<div class="document-wrapper"></div>
like image 308
user1898657 Avatar asked Mar 01 '13 17:03

user1898657


People also ask

How to remove classes in jQuery?

The removeClass() method removes one or more class names from the selected elements. Note: If no parameter is specified, this method will remove ALL class names from the selected elements.

How do I remove all classes from an element?

To remove all classes from an element, set the element's className property to an empty string, e.g. box. className = '' . Setting the element's className property to an empty string empties the element's class list.

How do you delete multiple classes?

Approach: First select the element to which multiple classes will be added. Then use addClass() method to add multiple classes to the element and removeClass() method to remove multiple classes.

How to removeClass in JavaScript?

To remove a class from an element, you use the remove() method of the classList property of the element.


2 Answers

$('.document-wrapper').removeClass().addClass('document-wrapper');

like image 145
Dom Avatar answered Nov 15 '22 08:11

Dom


Like this

$('.document-wrapper').removeClass().addClass('document-wrapper');
like image 33
Senad Meškin Avatar answered Nov 15 '22 06:11

Senad Meškin