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

Beginner
6 min read
Updated: Oct 2026
5 examples
Live preview

What Is [name!="value"]?

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']).

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

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

!=  ≈  :not([attr='value'])
faster: $("input").not("[name='newsletter']")
UsePrefer
Exclude one value$("input").not("[name='x']")
Exact value only$("[attr='x']")
Attribute present$("[attr]")

How to Use [name!="value"]

Exclude one exact attribute value — remembering that missing attributes also match.

  1. Choose the attribute and the value to exclude.
  2. For demos: $("input[name!='newsletter']").
  3. For production: $("input").not("[name='newsletter']") (official performance tip).
  4. Expect matches for other values and elements without the attribute.
PieceRequired?Role
attributeYesAttribute name to test
valueYesExact value to exclude
CSS base + .not()RecommendedFaster than bare != in modern browsers

Pseudocode

Pseudocode
attrName = given attribute
excluded = given value
matches  = empty list

for each element:
    if element does not have attrName:
        add element                   // missing attr matches
    else if element.getAttribute(attrName) != excluded:
        add element                   // different value matches

return jQuery(matches)

Cheat Sheet

Keep these facts handy while excluding attribute values.

TopicDetail
Syntax$("[attr!='value']")
MatchesMissing attr, or attr ≠ value
Classic use$("input[name!='newsletter']")
Equivalent:not([attr='value'])
Faster form$("sel").not("[attr='value']")
vs == is exact only; != is the inverse set
SincejQuery 1.0 (extension, not CSS)

Live Preview

Compare !=, =, and .not() against sample inputs and see which names match.

Sample markup mirrors the official jQuery name!='newsletter' demo.

Result
$("input[name!='newsletter']")
matched: 3
names: (none), accept, (none)

/* missing name OR name ≠ newsletter */

jQuery Examples

Short, copy-ready snippets. Open a browser with jQuery loaded, or use Try It Yourself for a live editor.

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.
  4. Official idea. Same exclusion used in the jQuery API demo.

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.
  4. Pick carefully. Need one value → =. Exclude one value → != or .not().

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.
  4. Why prefer it. Official docs: bare != cannot use querySelectorAll.

Example 4 — Missing Attributes Match !=

An element without the attribute is treated as “not equal” to the value.

jQuery
var labels = $("input[name!='newsletter']").map(function () {
  return (this.name ? this.name : "MISSING") + ":" + this.type;
}).get().join(", ");

console.log(labels);
Try It Yourself

How It Works

  1. No attribute. The checkbox has no name → it matches !=.
  2. Other value. accept is not newsletter → it matches.
  3. Exact value out. Anything named newsletter is excluded.
  4. Gotcha. If you only want “has name, but not X,” combine with [name] first.

Example 5 — Exclude a Control Type: type!="text"

Keep non-text inputs with the same not-equal pattern.

jQuery
var types = $("input[type!='text']").map(function () {
  return this.type;
}).get().join(", ");

console.log(types);
console.log("count:", $("input[type!='text']").length);
Try It Yourself

How It Works

  1. Exclude one type. type!='text' drops text fields.
  2. Keep others. Checkbox, radio, and submit remain.
  3. List types. Mapping shows the remaining control kinds.
  4. Production tip. Prefer $("input").not("[type='text']") for speed.

Edge Cases & Pitfalls

Check these before relying on != in real projects.

missing

Missing attributes match

[name!="x"] includes elements with no name. To require the attribute, use $("[name]").not("[name='x']").

perf

Bare != is slower

Official tip: use $("sel").not("[attr='value']") so the first pass can use native CSS selection.

ext

Not standard CSS

!= is a jQuery extension. Native querySelectorAll cannot run it directly.

case

Case-sensitive exclusion

name="Newsletter" is not equal to newsletter, so it still matches [name!="newsletter"].

Browser Support

The attribute not-equal selector [attr!="value"] is a jQuery extension since 1.0 — not standard CSS. It works wherever full jQuery runs; for speed, prefer .not("[attr='value']").

✓ jQuery 1.0+ · Extension

jQuery [name!="value"]

Supported in all browsers that run jQuery. Not available in native querySelectorAll. Recommended: $("input").not("[name='newsletter']").

100% With jQuery
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
!= extension jQuery only

Bottom line: Works everywhere jQuery runs. For modern performance, select with CSS first, then .not("[attr='value']").

Performance Notes

ApproachCostBest for
$("input").not("[name='x']")CSS pass + filterRecommended (official tip)
$("input[name!='x']")Sizzle extension pathSmall demos
$(":not([name='x'])")Similar intentWhen you already use :not()

Official docs: because != is not CSS, it cannot use querySelectorAll. Narrow with a pure CSS selector first, then .not().

Key Takeaways

  • Role: exclude one exact attribute value (missing attrs match too).
  • Classic use: $("input[name!='newsletter']") from the official demo.
  • Speed: prefer $("sel").not("[attr='value']").
  • Extension: not standard CSS — jQuery only.

One line: use != (or better, .not()) to exclude one exact attribute value — and remember missing attributes match.

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: [name|="value"]

Match exact values or hyphenated language-style prefixes.

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

9 people found this page helpful