jQuery Attribute Not Equal [name!="value"]

Beginner
5 min read
Updated: Nov 2026
3 examples
Selectors

Definition

The attribute not-equal selector matches elements that do not have the attribute, or have it with a value other than the given string. Available since jQuery 1.0 (jQuery extension). Equivalent to :not([attr='value']).

Syntax

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

jQuery
$("[attribute!='value']")

$("input[name!='newsletter']")
  ✓ no name attribute
  ✓ name="accept"
  ✗ name="newsletter"

!=  ≈  :not([attr='value'])
faster: $("input").not("[name='newsletter']")
CallWhat it does
See the examples below.

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

Parameters

ParameterDescription
Step 1Choose the attribute and the value to exclude.
Step 2For demos: $("input[name!='newsletter']").
Step 3For production: $("input").not("[name='newsletter']") (official performance tip).

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[name!="newsletter"]

List inputs that are not named newsletter (including those with no name).

jQuery
var names = $("input[name!='newsletter']").map(function () {
  return this.name || "(none)";
}).get().join(", ");

console.log(names);
console.log("count:", $("input[name!='newsletter']").length);
Try It Yourself

How It Works

  1. Scan inputs. The selector runs on every input.
  2. Exclude one name. Anything with name="newsletter" is dropped.
  3. Keep the rest. Other names and missing names both match.

Example 2 — != vs =

Exact equals and not-equals partition the set differently.

jQuery
console.log("=  :", $("input[name='newsletter']").length);
console.log("!= :", $("input[name!='newsletter']").length);

// = keeps only newsletter
// != keeps everything else (including no name)
Try It Yourself

How It Works

  1. Equals is narrow. Only the exact value matches.
  2. Not-equals is wide. Everything else — including missing attrs — matches.
  3. Compare counts. Lengths show the inverse relationship.

Example 3 — Faster Pattern: .not("[name='…']")

Official performance tip: CSS first, then exclude with .not().

jQuery
var $a = $("input[name!='newsletter']");
var $b = $("input").not("[name='newsletter']");

console.log($a.length === $b.length);
console.log("count:", $b.length);
Try It Yourself

How It Works

  1. CSS first. $("input") can use native selection.
  2. Then exclude. .not("[name='newsletter']") drops the unwanted value.
  3. Same size. Length matches the != form on this markup.

Frequently Asked Questions

It selects elements that either do not have the specified attribute, or have that attribute with a value that is not exactly equal to the given string. For example, [name!="newsletter"] matches inputs with no name and inputs where name is accept — but not name="newsletter".
No. It is a jQuery extension added in version 1.0. It is equivalent to :not([attr="value"]) in intent, but it is not part of the CSS specification and cannot use native querySelectorAll optimizations.
Yes. An input with no name attribute matches [name!="newsletter"] because it does not have name="newsletter".
Use a CSS selector plus .not(): $("input").not("[name='newsletter']"). This lets jQuery use native querySelectorAll for the first pass, then filter out matches.
Yes. Comparison follows the same case-sensitive rules as [attr="value"]. name="Newsletter" does not equal newsletter and would match [name!="newsletter"].
[name="newsletter"] matches only elements whose name is exactly newsletter. [name!="newsletter"] matches everything else — including elements with no name attribute.

Next: Attribute Contains Prefix Selector

Match exact values or hyphenated language-style prefixes.

Attribute Contains Prefix Selector 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