jQuery removeClass() Method

Beginner
6 min read
Updated: Oct 2026
4 examples
Live preview

What Is removeClass()?

.removeClass() removes one or more CSS class names from each matched element (since jQuery 1.0). Named classes are stripped; others stay. With no arguments, every class is cleared.

Remember
$("p").removeClass("blue")
$("p").removeClass("blue under")          // multiple (space)
$("p").removeClass(["blue", "under"])     // array (3.3+)
$("p").eq(1).removeClass()                // remove ALL classes

// Switch state:
$("p").removeClass("old").addClass("new")
NeedUse
Turn a style off$el.removeClass("active")
Turn a style on$el.addClass("active")
Flip on/off$el.toggleClass("active")
Replace all classes$el.attr("class", "only-this")

How to Use removeClass()

Select elements, pass class names to strip (or none to clear all), then chain if needed.

  1. Select the element(s) with a jQuery selector.
  2. Call .removeClass("name") — or a space list / array / callback.
  3. Omit arguments only when you truly want every class gone.
  4. Chain freely — .removeClass() returns the same jQuery object.
PieceRequired?Role
jQuery collectionYesElements to update
className / array / functionOptionalWhat to strip; omit = remove all
Return—Same jQuery object (chainable)

Pseudocode

Pseudocode
for each matched element:
    if no argument:
        clear entire class attribute
    else:
        names = resolve (string | array | function)
        for each class in names:
            remove it if present

// Official idea:
$("p").even().removeClass("blue")
// even-index paragraphs lose "blue"; other classes stay

Cheat Sheet

Keep these facts handy while stripping classes.

TopicDetail
Syntax.removeClass(className) or .removeClass()
SincejQuery 1.0 (array form: 3.3+)
MultipleSpace string or ["a", "b"]
Callbackfunction(index, className) since 1.4
No argsRemoves all classes
Missing nameSafe no-op for that name
SVG / XMLSupported since jQuery 1.12 / 2.2

Live Preview

Start from class="blue under highlight", run a remove action, and inspect the updated class attribute.

Browser demo of .removeClass() — same idea as the examples below.

Result
class before: "blue under highlight"
$("p").removeClass("blue")
class after:  "under highlight"

jQuery Examples

Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.

Example 1 — Remove One Class

Strip blue; leave other classes on the element.

jQuery
// <p class="blue under">Hello</p>
$("p").removeClass("blue");
console.log($("p").attr("class")); // "under"
Try It Yourself

How It Works

  1. Start. The paragraph has blue and under.
  2. Strip. removeClass("blue") targets only that name.
  3. Keep. under remains on the class attribute.
  4. Safe. Removing a name that is already absent is a no-op.

Example 2 — Multiple Classes (String or Array)

Remove several names in one call.

jQuery
// <p class="blue under highlight">Hello</p>
$("p").removeClass("blue under");
// same as: $("p").removeClass(["blue", "under"]);
console.log($("p").attr("class")); // "highlight"
Try It Yourself

How It Works

  1. List. Space-separated names (or an array since 3.3).
  2. Both gone. blue and under are removed.
  3. Remainder. highlight was not listed, so it stays.
  4. Array tip. Handy when class names already live in an array.

Example 3 — Remove All Classes

Call with no arguments to clear the entire class attribute.

jQuery
// <p class="blue highlight under">and</p>
$("p").eq(0).removeClass();
console.log($("p").eq(0).attr("class")); // "" (or undefined)
Try It Yourself

How It Works

  1. No args. Means “strip everything.”
  2. Result. The element no longer has stylesheet class hooks.
  3. Scope. Only matched elements are cleared — others are untouched.
  4. Replace tip. For a fresh single class, use .attr("class", "new").

Example 4 — Callback Form

Return class names to remove based on another element (official pattern).

jQuery
// <li class="beta">Prev</li>
// <li class="alpha beta gamma">Last</li>
$("li").last().removeClass(function () {
  return $(this).prev().attr("class"); // "beta"
});
console.log($("li").last().attr("class")); // "alpha gamma"
Try It Yourself

How It Works

  1. Per element. jQuery calls the function for the last <li>.
  2. Return value. Previous sibling’s class string is "beta".
  3. Strip. That name is removed from the last item.
  4. Keep. alpha and gamma were not returned, so they stay.

Edge Cases & Pitfalls

Check these before clearing classes in UI code.

all

Empty call removes everything

.removeClass() with no args is powerful — and easy to overuse. Prefer named removals when possible.

dot

No CSS selector dot

Write removeClass("active"), not removeClass(".active").

replace

Replace ≠ remove then guess

To set an exclusive class list, use .attr("class", "new") or removeClass().addClass() with known names.

missing

Missing names are fine

Removing a class that is not present does not throw — jQuery simply skips it.

Browser Support

.removeClass() is a core jQuery method (since 1.0). It needs a browser DOM with jQuery loaded. Array overload needs 3.3+. SVG/XML updates are solid since 1.12/2.2.

✓ jQuery 1.0+ · Browsers only

jQuery .removeClass()

Works in Chrome, Firefox, Safari, Edge, and other browsers with jQuery. Not for Node.js without a DOM.

100% Browser support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
.removeClass() Browsers

Bottom line: Use .removeClass() in the browser. Prefer named removals; reserve the no-arg form for a full clear.

Performance Notes

ApproachCostBest for
.removeClass("x")LowTurning off one UI state
.removeClass() (all)LowFull reset of class list
Native classList.removeLowestHot paths without jQuery

Class changes are cheap compared with layout thrashing. Prefer named removals over clearing everything when you only need one state gone.

Key Takeaways

  • Role: .removeClass() strips class names; others stay.
  • Many at once: space string or array (3.3+).
  • No args: clears every class on each match.
  • Switch: chain with .addClass() for exclusive states.

One line: use .removeClass() to turn stylesheet states off — named removals by default, empty call only for a full clear.

Frequently Asked Questions

.removeClass() strips one or more CSS class names from each matched element. Other classes stay. With no arguments, it removes every class from each match.
.removeClass() with no args clears the entire class attribute on every matched element. Use sparingly. To replace all classes with one new name, prefer .attr('class', 'newClass').
Yes. Pass a space-separated string — removeClass('blue under') — or since jQuery 3.3 an array — removeClass(['blue', 'under']).
Since jQuery 1.4 you can pass function(index, className). jQuery calls it once per element and removes the returned class name(s). Since 3.3 the callback may return an array.
.removeClass() always strips. .addClass() always appends. .toggleClass() flips presence. Chain removeClass().addClass() to switch exclusive states.
Yes, since jQuery 1.12/2.2 it updates the class attribute and supports SVG and XML elements.

Next: toggleClass()

Learn how to flip CSS classes on and off without a separate hasClass check.

toggleClass() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful