jQuery .removeClass() Method

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Class names

What You’ll Learn

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

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.

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.

📝 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)

jQuery
.removeClass( function( index, className ) {
  // return className string
} )
  • index — zero-based index of the element within the matched set.
  • className — the element’s current class attribute value (or empty string).
  • Return a string of class name(s) to remove for that element.

5. Function returning array (since 3.3)

The callback may return an array of class names instead of a space-separated string:

jQuery
$( "li" ).removeClass( function( index ) {
  return [ "item-" + index, "row-" + index ];
} );

Return value

  • The original jQuery object (for chaining) — not a new collection.

Official jQuery API swap pattern

jQuery
$( "p" ).removeClass( "myClass noClass" ).addClass( "yourClass" );

// Strip old classes, then append the new one — common state-switch pattern

⚡ Quick Reference

GoalCode
Remove one class$("p").removeClass("highlight")
Remove multiple classes (string)$("p").removeClass("blue under")
Remove multiple classes (array, 3.3+)$("p").removeClass(["blue", "under"])
Remove all classes$("p").removeClass()
Replace all classes at once$("p").attr("class", "newClass")
Switch state (remove then add)$(".tab").removeClass("active").addClass("active")

📋 .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

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.

jQuery
$( "p" ).even().removeClass( "blue" );
Try It Yourself

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.

jQuery
$( "p" ).odd().removeClass( "blue under" );
Try It Yourself

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.

jQuery
$( "p" ).odd().removeClass( [ "blue", "under" ] );
Try It Yourself

How It Works

The array form (added in jQuery 3.3) avoids building a space-separated string manually — handy when class names are computed or stored in an array.

Example 4 — Official Demo: Callback Removes Previous Sibling’s Classes

Remove whatever classes the previous list item carries — a dynamic callback pattern.

jQuery
$( "li" ).last().removeClass( function() {
  return $( this ).prev().attr( "class" );
} );
Try It Yourself

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.

jQuery
$( "p" ).eq( 1 ).removeClass();
Try It Yourself

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.

🚀 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.

📝 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().

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 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() Universal

Bottom line: Safe in any jQuery project. Prefer .removeClass() for stylesheet classes; use .css() for one-off inline values.

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.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about .removeClass()

Strip classes — or all with no args.

5
Core concepts
02

No args

Remove all

Syntax
+ 03

.addClass()

Pair

Compare
[] 04

Array

3.3+

Syntax
fn 05

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>.

Next: .toggleClass()

Learn how to flip CSS classes on and off with a single method call.

.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.

6 people found this page helpful