The jQuery removeClass() method, as the name suggests, is used lớn remove sầu one or more class names from a selector. For removing multiple class names, separate them using spaces.Quý khách hàng đang xem: How to remove all css classes using jquery?
Syntax of jQuery removeClass
|classname||Required Parameter: names of the classes to lớn be removed from the selector. If more than one, use space to lớn separate them.|
Bạn đang xem: How to remove all css classes using jquery?
|function(index,currentClass)||Optional Parameter: A function that returns one or more class names that are spaces-separated. The returned class names are removed from the selector.index: index position of the element in the selector.currentClass: current class names of the element in the selector.|
Example 2: Remove sầu 3 Class Names
I can remove more than one class from the selector using jQuery removeClass method.
Here I remove 3 CSS Classes from the paragraph element. These classes are red, fontBold and borderSolid.In the above jQuery removeClass code I gave sầu the three classes name separated by space.
Example 3: Using jQuery removeClass Function Parameter
The class names returned by this function are removed from the selector.
Xem thêm: thẻ in hoa trong html
I have sầu 3 paragraph element, 2 have red và fontBold classes while the 3rd has fontBold class.
Now I want khổng lồ remove sầu red và borderSolid classes from these paragraphs.
First Paragraph with class "Red"
Second Paragraph with class "Red"
Third Paragraph without any classAdd Class
$("#myButton").click(function (e) $("p").removeClass(function (index, currentClass) return "red borderSolid"; ););I returned red borderSolid from the function and these 2 classes will be removed from the selector.
Cheông chồng the chạy thử & download links:
Note: Obviously the 3rd paragraph which has the fontBold class remains unharmed.
Subscribe to receive notifications of new posts by gmail. Join over 81,000 other subscribers
Don't worry we won't spam. Only 2 Emails in a Week.
Please Share This Tutorial. Thank You!
SUBSCRIBE TO NEWSLETTER
Enter your email address khổng lồ subscribe to lớn this blog and receive sầu notifications of new posts by email
Join 90K other subscribers
Subscribe lớn our Newsletter & connect with the growing community of Programmer, Bloggers, Marketers and SEO professionals around the world.