jQuery .not() Method

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

What You’ll Learn

The .not() traversing method excludes elements from the current jQuery collection — it keeps everything that does not match your selector, callback, DOM node, or jQuery object. This tutorial covers the official list and div demos, DOM-element exclusion, comparisons with .filter() and .is(), and callback-based removal.

01

Exclude

Remove matches

02

Selector

.not(".x")

03

Callback

Since 1.4

04

DOM node

Remove one

05

vs .filter()

Inverse

06

Since 1.0

Core API

Introduction

Often you need to act on almost every element in a selection — all list items except one, all divs except green and blue, all inputs except disabled ones. The .not() method removes unwanted elements from the current set so you can style or manipulate the rest.

Available since jQuery 1.0 (callback and jQuery-object forms since 1.4), .not() is the inverse of .filter(). Where .filter() keeps matches, .not() keeps non-matches. The returned jQuery object is a new subset — the original collection is unchanged until you reassign the variable.

Understanding the .not() Method

Given a jQuery object representing a set of DOM elements, .not(selectorOrFunctionOrElement) tests each element against the argument. Elements that match are dropped; everything else stays in the result. With a callback, returning true excludes the element — the opposite of .filter(), where true means keep.

This is set narrowing, not tree traversal. .not() only considers elements already in the current collection — it does not search descendants or siblings. Compare with .find(), which drills down, and .is(), which returns a boolean without changing the set.

💡
Beginner Tip

$("li").not(":nth-child(2n)") excludes even-position items — items 2 and 4 — leaving 1, 3, and 5. The same pattern with .filter(":nth-child(2n+1)") would keep the same result.

📝 Syntax

General forms of .not:

jQuery
.not( selector )

.not( function )

.not( selection )

Parameters

  • selector — a string containing a selector expression, a DOM element, or an array of elements. Matching elements are removed from the set.
  • function — a callback receiving index and element. Elements for which the function returns true are excluded.
  • selection — an existing jQuery object. Elements in the current set that match nodes in this object are removed.

Return value

  • A new jQuery object containing elements from the current set that do not match the argument.

Official jQuery API list example

jQuery
$( "li" ).not( ":nth-child(2n)" ).css( "background-color", "red" );

// Red on items 1, 3, 5 — even-position items excluded

⚡ Quick Reference

GoalCode
Exclude by class$("li").not(".active")
Exclude multiple selectors$("div").not(".green, #blueone")
Remove one DOM node$("li").not(document.getElementById("skip"))
Exclude via callback$("input").not(function(){ return this.disabled; })
Keep matches instead$("li").filter(".active")
Boolean test only$("li").is(".active")

📋 .not() vs .filter() vs .is()

Three methods that test the current set — exclude, keep, or boolean-check.

.not()
exclude

Remove matches — keep non-matches

.filter()
keep

Keep matches — drop non-matches

.is()
true/false

Test set — no new collection returned

Callback
opposite

true excludes in .not(); true keeps in .filter()

Examples Gallery

Examples 1–3 follow the official jQuery API documentation. Use DevTools or the Try-it links to run each snippet in the browser.

📚 Getting Started

Official jQuery demos for excluding elements from a matched set.

Example 1 — Official Demo: Exclude Even List Items

Style list items that are not on even positions — the core official list lesson.

jQuery
$( "li" ).not( ":nth-child(2n)" ).css( "background-color", "red" );
Try It Yourself

How It Works

:nth-child(2n) matches items 2 and 4. .not() removes them from the set before .css() runs on items 1, 3, and 5.

Example 2 — Official Demo: Exclude a Specific DOM Element

Remove one list item by native DOM reference — useful when another library provides the node.

jQuery
$( "li" ).not( document.getElementById( "notli" ) )

  .css( "background-color", "red" );
Try It Yourself

How It Works

Passing a DOM node to .not() removes that exact element if it appears in the current set. Equivalent to .not("#notli") when the id is known.

Example 3 — Official Demo: Border on Divs That Are Not Green or Blue

Exclude multiple selectors — divs without class green and without id blueone.

jQuery
$( "div" ).not( ".green, #blueone" )

  .css( "border-color", "red" );
Try It Yourself

How It Works

Comma-separated selectors in .not() exclude any element matching either rule. Green and blue divs stay untouched; the rest get the red border.

📈 Practical Patterns

Compare with .filter(), then exclude via callback logic.

Example 4 — .not() vs .filter() on the Same Set

See how opposite logic produces complementary subsets.

jQuery
$( "#not-demo li" ).not( ".active" ).css( "color", "gray" );

$( "#filter-demo li" ).filter( ".active" ).css( "color", "blue" );



// .not('.active') → inactive | .filter('.active') → active
Try It Yourself

How It Works

Together, .not('.active') and .filter('.active') partition the same list into inactive and active groups — mutually exclusive subsets covering the whole set.

Example 5 — Exclude Disabled Inputs with a Callback

Use the function form when exclusion logic is more than a simple selector.

jQuery
$( "input" ).not( function() {

  return this.disabled;

}).addClass( "enabled-field" );
Try It Yourself

How It Works

Returning true from the callback excludes the element. Here, disabled inputs are dropped; enabled ones receive the class — the callback mirror of .filter(function(){ return !this.disabled; }).

🚀 Common Use Cases

  • Skip one item$("li").not("#skip") or DOM-node exclusion.
  • All except active$(".tab").not(".active") for inactive tabs.
  • Form fields minus disabled — callback or .not(":disabled").
  • Exclude highlighted types — official pattern: $("div").not(".green, #blueone").
  • Remove known selection$("p").not($("#selected")) when you already have a jQuery object.
  • Stripe inverse$("tr").not(":nth-child(even)") for odd rows only.

🧠 How .not() Excludes From the Matched Set

1

Start with current set

jQuery object holds candidate elements.

Input
2

Test each element

Selector, callback, DOM node, or jQuery object.

Test
3

Drop matches

Matching elements are removed from the result.

Exclude
4

Return & chain

New subset — push stack for .end().

📝 Notes

  • Available since jQuery 1.0 — callback and jQuery-object forms since 1.4.
  • Inverse of .filter() — same arguments, opposite keep/exclude logic.
  • Callback returning true excludes the element (opposite of .filter()).
  • Only narrows the current set — does not search descendants like .find().
  • With a CSS selector string, text and comment nodes are removed during filtering.
  • Pushes onto jQuery’s internal stack — pair with .end() to restore the previous set.

Browser Support

.not() has been part of jQuery since 1.0+ (function form since 1.4). It relies on selector matching with no browser-specific behavior beyond jQuery itself.

jQuery 1.0+

jQuery .not()

Supported in jQuery 1.x, 2.x, and 3.x across all modern browsers and IE with supported jQuery builds. Native equivalent: manual array filter — jQuery .not() integrates with the collection stack and selector engine.

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

Bottom line: Safe in any jQuery project. Use .not() to exclude; use .filter() when you need to keep matches.

Conclusion

The jQuery .not() method removes elements from the current collection — keeping everything that does not match your selector, callback, DOM node, or jQuery object. It is the natural inverse of .filter() for set narrowing.

Remember the official list lesson: $("li").not(":nth-child(2n)") styles items 1, 3, and 5 by excluding even positions. Reach for .filter() when you want to keep matches, and .is() when you only need a true/false answer.

💡 Best Practices

✅ Do

  • Use .not() when exclusion reads clearer than inverted .filter()
  • Pass DOM nodes when another API gave you a plain element reference
  • Combine comma selectors to exclude multiple types at once
  • Pair mentally with .filter() — opposite logic, same set
  • Call .end() after .not() when continuing on the full set

❌ Don’t

  • Use .not() when you need to keep matches — use .filter()
  • Confuse .not() with .remove() — .not() does not delete DOM nodes
  • Expect .not() to search inside elements — use .find() first
  • Return false from a callback expecting exclusion — true means exclude
  • Use .is() when you need a modified collection to chain further

Key Takeaways

Knowledge Unlocked

Five things to remember about .not()

Remove matches — keep the rest.

5
Core concepts
+ 02

.filter()

Inverse

Compare
? 03

.is()

Boolean

Compare
fn 04

Callback

true drops

Logic
DOM 05

Node arg

Remove one

API

❓ Frequently Asked Questions

.not() removes elements from the current jQuery collection — it returns a new jQuery object containing only elements that do NOT match a selector, fail a callback test, or match a provided DOM element or jQuery object. It is the inverse of .filter().
.filter() keeps elements that match. .not() keeps elements that do not match. $('li').filter('.active') returns active items; $('li').not('.active') returns inactive ones. Same test, opposite result set.
.is() returns a boolean — true if at least one element in the set matches. .not() returns a new jQuery object with matching elements removed. Use .is() to test; use .not() to exclude and keep working with the remaining collection.
Yes, since jQuery 1.4. .not(domElement) removes that specific node from the set if present. .not($('#selected')) removes elements that match nodes in the jQuery object — useful when another library gave you a plain DOM reference.
.not(function(index, element) { ... }) runs once per element. If the function returns true, that element is excluded from the result. Inside the callback, this refers to the current DOM element — the opposite logic of .filter(), where true means keep.
No. .not() only changes which elements the jQuery object refers to. It does not remove nodes from the page — though you may chain .remove() or .hide() on the filtered result afterward.
Did you know?

jQuery added the callback form of .not() in version 1.4 alongside .filter(function) — same signature, inverted boolean meaning. Before that, developers often wrote .filter(function(){ return !condition; }); .not(function){ return condition; } expresses exclusion more directly.

Back to jQuery Traversing

Explore more DOM traversal methods as the collection grows.

Traversing hub →

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