The .removeClass() method strips one or more CSS class names from each matched element — call it with no arguments to remove every class. This tutorial covers all four API overloads (no-args, string, array, callback), comparisons with .addClass(), .toggleClass(), and .css(), and the official swap pattern with .addClass().
01
No args
.removeClass()
02
String
Space-separated
03
Array
Since 3.3
04
Callback
Per element
05
vs add
Switch classes
06
Since 1.0
Core API
Fundamentals
Introduction
Styling in modern web pages usually lives in CSS files — reusable class names like .active, .error, or .hidden that you toggle on elements at runtime. When JavaScript needs to turn a style off, jQuery provides .removeClass().
Available since jQuery 1.0, .removeClass() updates the class attribute on each matched element. It strips specified class names while leaving others intact — or removes every class when called with no arguments. It is often paired with .addClass() to switch states. For inline property values, use .css() instead.
Concept
Understanding the .removeClass() Method
Given a jQuery object representing one or more DOM elements, .removeClass() removes the specified class name(s) from each element’s class attribute. Styles defined in your stylesheet for those classes stop applying immediately — no need to clear individual CSS properties in JavaScript.
Think of classes as labels you stick onto elements. .addClass() adds more labels; .removeClass() peels them off; .toggleClass() flips a label on or off. To replace every class at once, set the attribute directly: .attr("class", "newClass").
💡
Beginner Tip
$("p").even().removeClass("blue") strips blue from even paragraphs only — every other class on those elements stays untouched.
Foundation
📝 Syntax
jQuery .removeClass() accepts four argument forms:
1. No arguments — remove all classes (since 1.0)
jQuery
.removeClass()
Removes every class from each matched element. On some older browsers, removing the last class may leave an empty string on the attribute.
2. String — one or more class names (since 1.0)
jQuery
.removeClass( className )
className — a string of one or more space-separated CSS class names to remove from each matched element.
3. Array — list of class names (since 3.3)
jQuery
.removeClass( [ classNames ] )
classNames — an array of strings; jQuery removes every entry from each element.
4. Function — per-element class name(s) (since 1.4)
📋 .removeClass() vs .addClass() vs .toggleClass() vs .css()
Four styling approaches — strip classes, append classes, flip classes, or set inline properties.
.removeClass()
- class
Strip one, some, or all classes
.addClass()
+ class
Append class names — keeps existing classes
.toggleClass()
on/off
Add if missing, remove if present
.css()
inline
Set style properties directly on the element
Hands-On
Examples Gallery
Examples 1–4 follow the official jQuery API documentation. Example 5 shows removing every class with no arguments. Use DevTools or the Try-it links to run each snippet in the browser.
📚 Getting Started
Official jQuery demos for removing CSS classes.
Example 1 — Official Demo: Remove blue From Even Paragraphs
Strip the blue class from every even-indexed paragraph.
Even paragraphs (0, 2, 4…) → class "blue" removed
Odd paragraphs → still blue
Other classes on even paragraphs → unchanged
How It Works
.even() narrows to even-indexed elements, then .removeClass("blue") strips only that class. Odd paragraphs and any other classes on the even ones stay as they were.
Example 2 — Official Demo: Remove Two Classes With a String
Pass a space-separated string to remove multiple classes in one call.
Odd paragraphs → classes "blue" and "under" removed
Even paragraphs → still styled with blue and underline
Remaining classes on odd paragraphs → preserved
How It Works
jQuery splits the string on spaces and removes each listed class name. Both stylesheet rules stop applying to the odd paragraphs simultaneously.
Example 3 — Official Demo: Array Syntax (jQuery 3.3+)
Pass an array when you already have class names in a JavaScript array.
Last li → classes matching previous sibling's class attribute removed
Previous li → unchanged
Demonstrates dynamic class removal via callback return value
How It Works
jQuery invokes the callback once per matched element. The returned string (or array since 3.3) tells jQuery which class name(s) to strip. Here, the last item loses whatever classes its previous sibling had.
📈 Practical Patterns
Use no-argument .removeClass() to wipe every class, or chain with .addClass() for exclusive state switches.
Example 5 — Remove All Classes With No Arguments
Calling .removeClass() with no arguments strips every class from the matched element.
Second paragraph (index 1) → all classes removed
class attribute → empty (or empty string on older browsers)
Other paragraphs → unchanged
How It Works
With no arguments, jQuery clears every class from each matched element. To replace all classes with a single new one, prefer .attr("class", "newClass") instead of remove-then-add.
Applications
🚀 Common Use Cases
Tab or nav switch — $(".tab").removeClass("active"); $(this).addClass("active").
Clear validation errors — $("input").removeClass("error") after the user fixes a field.
Reset styling state — $(".panel").removeClass("visible hidden") before applying a new state.
Official swap pattern — $("p").removeClass("myClass noClass").addClass("yourClass").
Wipe all classes — $("div").removeClass() when you need a clean slate (use sparingly).
Replace every class — $(this).attr("class", "newState") when you want one class only, not a chain.
🧠 How .removeClass() Updates Elements
1
Match elements
jQuery object holds one or more DOM nodes to update.
Input
2
Resolve class names
No args clears all; string, array, or callback names classes to strip.
Parse
3
Update class attribute
Listed classes removed — others stay. No args removes everything.
DOM
4
🎨
Styles update
CSS rules for removed classes stop applying — return same jQuery object for chaining.
Important
📝 Notes
Available since jQuery 1.0 — core class manipulation API.
Often paired with .addClass() to switch classes — e.g. the official .removeClass("myClass noClass").addClass("yourClass") pattern.
No arguments removes all classes from each matched element.
Array argument supported since jQuery 3.3; callback since 1.4 (callback may return array since 3.3).
Before jQuery 1.12/2.2 used the className property; since 1.12/2.2 uses the class attribute — works on SVG and XML elements.
Removing the last class may leave an empty string on the attribute in older browsers.
To replace all classes at once, use .attr("class", "newClass") instead of chaining remove and add.
Returns the original jQuery object for chaining — e.g. .removeClass("x").fadeIn().
Compatibility
Browser Support
.removeClass() has been part of jQuery since 1.0+. Array arguments arrived in 3.3+; SVG/XML support via the class attribute in 1.12+/2.2+. It relies on standard class attribute manipulation with no browser-specific quirks beyond jQuery itself.
✓ jQuery 1.0+
jQuery .removeClass()
Supported in jQuery 1.x, 2.x, and 3.x across all modern browsers and IE with supported jQuery builds. Native equivalent: element.classList.remove() — jQuery adds collection semantics, no-args remove-all, callback forms, and older-browser consistency.
100%With jQuery loaded
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
.removeClass()Universal
Bottom line: Safe in any jQuery project. Prefer .removeClass() for stylesheet classes; use .css() for one-off inline values.
Wrap Up
Conclusion
The jQuery .removeClass() method strips one or more CSS class names from each matched element — or every class when called with no arguments. It is the standard way to turn stylesheet-defined styles off at runtime — without touching inline properties.
Remember the official swap pattern: $("p").removeClass("myClass noClass").addClass("yourClass"). Chain .addClass() when switching exclusive states, reach for .toggleClass() for simple on/off, use .attr("class", "newClass") to replace all classes at once, and use .css() only when you need dynamic inline values.
Define reusable styles in CSS and toggle them with .removeClass() and .addClass()
Use the official swap pattern — .removeClass("old").addClass("new") — for state switches
Use the array form when class names come from a JavaScript array (3.3+)
Use .attr("class", "newClass") when you want to replace every class in one step
Keep class names semantic — .active, .error, not .red-text
❌ Don’t
Call .removeClass() with no arguments unless you truly want every class gone
Use .removeClass() for one-off pixel values — use .css() instead
Forget that .toggleClass() may be simpler for binary on/off states
Assume removed classes are gone from the DOM permanently — you can .addClass() them back anytime
Rely on empty-string edge cases in very old browsers — test if you support legacy IE
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about .removeClass()
Strip classes — or all with no args.
5
Core concepts
−01
.removeClass()
Strip
API
∅02
No args
Remove all
Syntax
+03
.addClass()
Pair
Compare
[]04
Array
3.3+
Syntax
fn05
Callback
Per item
1.4+
❓ Frequently Asked Questions
.removeClass() strips one or more CSS class names from each element in the current jQuery collection. It updates the element's class attribute so stylesheet rules for those classes no longer apply — without changing HTML content or inline style properties.
Calling .removeClass() with no arguments removes every class from each matched element — the class attribute becomes empty (or an empty string on some older browsers). Use this sparingly; to replace all classes with a single new one, prefer .attr('class', 'newClass') instead.
.removeClass() strips class names for stylesheet-driven styling. .addClass() appends classes. .toggleClass() adds a class when missing and removes it when present. .css() sets inline style properties directly — it does not touch the class attribute.
Yes. Pass a space-separated string — removeClass('blue under') — or since jQuery 3.3 an array — removeClass(['blue', 'under']). jQuery removes every listed class from each matched element. Classes not in the list stay on the element.
Since jQuery 1.4, you can pass a function: removeClass(function(index, className) { return 'highlight'; }). jQuery calls it once per element and removes the returned class name(s). Since 3.3 the callback may return an array of class names to strip.
Yes, since jQuery 1.12/2.2 .removeClass() uses the class attribute (not the legacy className property) and supports SVG and XML elements. To replace every class with a fresh set in one step, use .attr('class', 'newClass') instead of remove-then-add.
Did you know?
jQuery’s .removeClass() has existed since version 1.0 — one of the earliest DOM manipulation methods. Calling it with no arguments removes every class from each matched element, a behavior unique among the class methods. Since jQuery 1.12/2.2 it uses the class attribute (not the legacy className property), so it works on SVG elements too — peel .highlighted off an icon path the same way you would a <div>.