jQuery :not() Selector

Beginner
5 min read
Updated: Nov 2026
3 examples
Selectors

Definition

:not(selector) selects elements that do not match the given filter. Attach it to a base selector to subtract a group. Available since jQuery 1.0.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$(":not(selector)")
$("base:not(filter)")

$("li:not(.active)")           → all li except .active
$("input:not(:checked)")       → unchecked inputs
$("div:not(.skip, .draft)")    → exclude several classes
$("input:not(:checked) + span") → span after unchecked input
CallWhat it does
Base selectorElements to start from (optional if :not() stands alone)
:not(…)Negation filter
Inner selectorWhat to exclude — any valid selector

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Choose a base set — li, input, div, and so on.
Step 2Add :not(filter) with any valid selector inside.
Step 3Chain a method on the remaining matches.

Return Value

Return ValueDescription
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

Example 1 — Official Demo: input:not(:checked) + span

Select spans that sit right after unchecked inputs (jQuery API example).

jQuery
var labels = $("input:not(:checked) + span").map(function () {
  return this.textContent.trim();
}).get().join(", ");

console.log($("input:not(:checked)").length);
console.log(labels);
Try It Yourself

How It Works

  1. Negate checked. input:not(:checked) keeps only unchecked boxes.
  2. Step to the span. + span takes the immediate next sibling if it is a span.
  3. Read labels. Map text content for a clear console list.

Example 2 — Exclude a Class: li:not(.active)

Keep every list item except those marked active.

jQuery
$("li:not(.active)").each(function () {
  this.textContent = "[ok] " + this.textContent;
});

console.log($("li:not(.active)").length);
Try It Yourself

How It Works

  1. Start with all li. Then drop any with class active.
  2. Prefix the rest. Remaining items show [ok].
  3. Active untouched. The excluded item never enters .each().

Example 3 — Comma Exclusions: div:not(.skip, .draft)

Exclude several classes in one :not() filter.

jQuery
var names = $("div:not(.skip, .draft)").map(function () {
  return this.className || "(none)";
}).get().join(", ");

console.log($("div:not(.skip, .draft)").length);
console.log(names);
Try It Yourself

How It Works

  1. List exclusions. Comma-separated selectors inside :not() are all removed.
  2. Keep the rest. Only .keep (or other non-matching divs) remain.
  3. Official support. Docs allow forms like :not(div,a).

Frequently Asked Questions

:not(selector) keeps elements that do not match the inner selector. $("li:not(.active)") returns every list item except those with class active.
jQuery accepts any valid selector inside the parentheses — elements, classes, IDs, attributes, and other pseudo-classes. Official docs show both :not(div a) and :not(div,a).
:not() is part of a CSS selector string. .not() is a method that removes items from an existing jQuery collection. For complex or dynamic exclusions, official docs recommend .not() for readability.
Yes. Use a comma-separated list: $("div:not(.skip, .draft)"). Each listed selector is excluded.
No. Like other selectors, it matches the DOM at query time. Recheck after user actions if state changes (for example, checkboxes).
Since jQuery 1.0. Modern browsers also support CSS :not() via querySelectorAll; jQuery extends complex and comma-separated cases.

Next: Child Selector (parent > child)

Select direct children with the parent > child combinator.

Child Selector (parent > child) tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

9 people found this page helpful