The :not() selector is jQuery’s negation filter: it keeps every element that does not match the selector inside the parentheses. Available since jQuery 1.0, it is ideal for “everything except…” queries — unchecked inputs, inactive menu items, or visible fields minus hidden tokens.
01
Syntax
:not(selector)
02
Exclude
Skip matched nodes
03
Classes
:not(.active)
04
Official
input:not(:checked)
05
Lists
:not(.a, .b)
06
.not()
Method alternative
Fundamentals
Introduction
Most jQuery selectors answer “give me elements that look like this.” The :not() pseudo-class flips the question: “give me elements that do not look like this.” You attach it to a base selector — for example input:not(:checked) means “every input except the checked ones.”
This pattern shows up constantly in UI work: dim inactive tabs, style unchecked labels, skip hidden CSRF fields, or highlight published cards while ignoring drafts. Official jQuery documentation also notes that the .not() method is often easier to read when exclusions get complex — both approaches are covered here.
Concept
Understanding the :not() Selector
Think of :not() as a gate at the end of a selector. jQuery first finds candidates matching the part before:not(), then removes any that also match the filter inside the parentheses.
li:not(.active) → all li elements except those with class active.
input:not(:checked) → inputs that are not currently checked.
div:not(.sidebar) → every div except sidebar blocks.
div:not(.skip, .draft) → exclude two classes in one expression.
💡
Beginner Tip
Read :not() aloud: “not this.” The base selector sets the pool; the inner selector defines what to subtract. Start with a simple class exclusion like :not(.hidden) before combining pseudo-classes.
selector — any valid jQuery/CSS selector (or comma-separated list) describing elements to exclude from the result.
Return value
A jQuery object containing every element that matched the base selector and did not match the inner filter.
An empty collection when every candidate is excluded or none exist.
Official jQuery API example
jQuery
// Highlight span labels beside unchecked inputs
$( "input:not(:checked) + span" ).css( "background-color", "yellow" );
// Disable inputs so the demo state stays fixed
$( "input" ).attr( "disabled", "disabled" );
Cheat Sheet
⚡ Quick Reference
Goal
Selector
Exclude a class
li:not(.active)
Exclude checked inputs
input:not(:checked)
Exclude hidden fields
input:not([type=hidden])
Exclude multiple classes
div:not(.a, .b)
Method alternative
$("li").not(".active")
Compare
📋 :not() vs .not() Method
Both remove matches — choose based on readability and whether you already hold a collection.
:not()
button:not(.ghost)
CSS selector filter
.not()
$("button").not(".ghost")
Traverse existing set
Dynamic
.not(myVariable)
Variables & functions
Official tip
Prefer .not()
When complex
Hands-On
Examples Gallery
Example 1 follows the official jQuery demo. Examples 2–5 cover class exclusions, attribute filters, comma-separated lists, and the .not() method. Use the Try-it links to run each snippet in the browser.
📚 Official jQuery Demo
Highlight labels beside unchecked inputs — the canonical :not() example from the API docs.
Example 1 — Official Demo: input:not(:checked) + span
Find every input that is not checked, then style the adjacent span sibling yellow. Inputs are disabled so the demo state stays visible.
Unchecked input labels (e.g. "lcm") get yellow background
Checked inputs (Mary, Peter) — adjacent spans stay default
Clicking has no effect — inputs are disabled
How It Works
:not(:checked) removes checked boxes from the input pool. The adjacent sibling combinator + span then targets only the label beside each remaining unchecked input.
📈 Practical Patterns
Classes, attributes, lists, and the traversal method.
Example 2 — Exclude Active Tab: li:not(.active)
Dim every navigation item except the currently active one.
jQuery
$( "#nav li:not(.active)" ).addClass( "dimmed" );
// Only non-active items receive the dimmed class
Dashboard (active) — full opacity
Reports, Settings, Help — dimmed with .dimmed class
How It Works
The base selector li gathers every item; :not(.active) subtracts the highlighted tab. This is one of the most common beginner uses of negation.
Example 3 — Skip Hidden Fields: input:not([type=hidden])
Count or validate only visible form inputs, excluding CSRF tokens and other hidden values.
jQuery
var visible = $( "#signup input:not([type=hidden])" ).length;
$( "#count" ).text( visible + " visible input(s)" );
// Hidden csrf field is excluded from the count
:not(.ghost) matched 2 button(s) — Save, Delete
.not('.ghost, .danger') matched 1 button(s) — Save only
How It Works
Both approaches subtract matches, but .not() runs on a collection you already selected — ideal for chaining and dynamic values. Keep :not() for straightforward one-line selectors.
Applications
🚀 Common Use Cases
Form styling — highlight labels beside input:not(:checked).
Navigation — dim li:not(.active) menu items.
Validation — operate on visible fields with input:not([type=hidden]).
Content filters — show published items via div:not(.draft).
Table rows — select tr:not(.empty-row) for bulk actions.
Refactoring — replace long negative logic with a readable .not() chain.
🧠 How jQuery Evaluates :not()
1
Parse selector
Split the string into a base part (e.g. input) and the :not(...) filter.
Syntax
2
Find candidates
Collect every element matching the base selector within the search context.
Query
3
Apply negation
Remove any candidate that also matches the inner selector (or any comma-separated exclusion).
Filter
4
📦
Return collection
Remaining elements become a jQuery object ready for .css(), .addClass(), or events.
Important
📝 Notes
Available since jQuery 1.0 — one of the oldest jQuery selector extensions built on standard CSS negation.
All selector types are accepted inside the parentheses, including combinators and nested pseudo-classes.
Official docs: .not() often produces more readable code than deeply nested :not() strings.
Comma-separated lists inside :not() exclude multiple patterns in one pass (:not(.a, .b)).
Scope matters — $("#form input:not(:checked)") only searches inside the form.
Native document.querySelectorAll supports :not() in modern browsers; jQuery adds consistent behavior across older targets.
Compatibility
Browser Support
The :not() pseudo-class is part of CSS3 and works in jQuery 1.0+. Modern browsers support negation in native querySelectorAll; jQuery’s Sizzle engine handles comma-separated exclusions consistently.
✓ CSS3 · jQuery 1.0+
jQuery :not() Selector
Supported in all modern browsers. Native: document.querySelectorAll("li:not(.active)"). jQuery extends negation with comma-separated lists inside :not().
100%Standard + jQuery
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
:not()Universal
Bottom line: Safe for modern apps. Prefer .not() when exclusions involve variables, functions, or jQuery objects — official docs recommend it for complex filters.
Wrap Up
Conclusion
The :not() selector answers exclusion questions in a single CSS-style expression — unchecked inputs, inactive tabs, visible fields minus hidden tokens. The official input:not(:checked) + span demo shows how negation pairs naturally with sibling combinators.
Start with simple class filters like :not(.hidden), then reach for .not() when the logic grows beyond what you want to cram into one selector string.
Scope with a parent ID: $("#form input:not(:checked)")
Use :not(.class) for simple single exclusions
Switch to .not() when filters get complex
Combine with other pseudo-classes: input:not(:checked)
Test Try-it labs to see live DOM filtering
❌ Don’t
Stack many nested :not() calls — use .not()
Forget the base selector — bare :not(.x) is invalid alone
Assume :not() mutates the DOM — it only filters results
Confuse :not(.a .b) (descendant inside) with :not(.a, .b) (two exclusions)
Overuse negation when a positive selector would be clearer
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about :not()
Exclude matches cleanly in jQuery selectors.
5
Core concepts
📝01
:not()
Negation filter
API
!02
Exclude
Subtract matches
Logic
,03
Lists
:not(.a, .b)
Multi
.not04
Method
When complex
Tip
✓05
Official
unchecked + span
Demo
❓ Frequently Asked Questions
:not(selector) matches every element in the search context that does NOT satisfy the inner selector. $("li:not(.active)") returns all list items except those with class active. It is a filter you attach to a base selector.
jQuery accepts any valid selector inside the parentheses — element types, classes, IDs, attributes, and other pseudo-classes. Official docs show both :not(div a) for complex filters and :not(div,a) for comma-separated exclusions.
:not() is part of a CSS selector string evaluated when jQuery queries the DOM. .not() is a jQuery method that removes items from an existing collection. For complex exclusions, .not() is often more readable than nesting long strings inside :not().
Yes. Use a comma-separated list inside the parentheses: $("div:not(.skip, .draft)"). Each comma-separated selector is excluded independently.
Yes. CSS3 defines :not() and modern browsers support it in querySelectorAll. jQuery has supported :not() since version 1.0 and extends it with comma-separated lists in some cases beyond early CSS levels.
Prefer .not() when you already have a jQuery collection, when the exclusion involves a variable or dynamic filter, or when the negation logic would make a single selector string hard to read. Official jQuery docs recommend .not() for readability in most complex cases.
Did you know?
Official jQuery documentation states that the .not() method usually produces more readable selections than pushing complex variables into a :not() filter. Both subtract matches — choose the form that your teammates can scan fastest.