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>
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.
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.
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.
To remove a class from an element, you use the remove() method of the classList property of the element.
$('.document-wrapper').removeClass().addClass('document-wrapper');
Like this
$('.document-wrapper').removeClass().addClass('document-wrapper');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With