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

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
jQuery extension

What You’ll Learn

The attribute not-equal selector — written [name!="value"] — matches elements that do not have the attribute set to your exact value. It also matches elements without that attribute. It is a jQuery extension (since 1.0), equivalent in intent to :not([attr="value"]).

01

Syntax

[attr!="x"]

02

Exclude

Not exact value

03

Missing

Attr absent too

04

Official

name!=newsletter

05

vs =

Inverse logic

06

.not()

Faster pattern

Introduction

Sometimes you need to select everything except one known attribute value — all inputs that are not hidden fields, all links that are not target="_blank", or every radio that is not part of the newsletter group.

The not-equal syntax [attribute!="value"] is jQuery’s way to express that exclusion. Unlike standard CSS attribute operators, this selector is a jQuery extension available since version 1.0. Official docs note it is equivalent to :not([attr="value"]) in behavior.

Understanding the Not-Equal Selector

Think of a checklist. The selector asks: “Is this attribute either missing, or set to something other than my value?” If yes, the element matches.

  • name="newsletter" + [name!="newsletter"] → no match.
  • name="accept" + [name!="newsletter"] → matches (different value).
  • no name attribute + [name!="newsletter"] → matches (attribute absent).
  • type="text" + [type!="hidden"] → matches.
💡
Beginner Tip

Elements without the attribute also match [attr!="value"]. If you only want elements that have the attribute but a different value, filter further or use .filter() with a custom test.

📝 Syntax

Official jQuery API form (since 1.0):

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

// common patterns:
$( "input[name!='newsletter']" )
$( "input[type!='text']" )

// faster alternative (official recommendation):
$( "input" ).not( "[name='newsletter']" )

Parameters

  • attribute — the HTML attribute name (name, type, value, etc.).
  • value — exact string to exclude (case-sensitive). Can be a valid identifier or a quoted string.

Return value

  • A jQuery object containing elements without the attribute or with a different value.
  • Empty collection only when every candidate has the excluded value.

Official jQuery API example

jQuery
$( "input[name!='newsletter']" ).next().append( "<b>; not newsletter</b>" );

// Matches: no name attribute, name="accept"
// Skips: name="newsletter"

⚡ Quick Reference

Element[name!="newsletter"]
name="newsletter"No match
name="accept"Matches
no name attributeMatches
name="Newsletter"Matches (case differs)
name="newsletter_extra"Matches (not exact value)

📋 [attr!="x"] vs [attr="x"]

Equals includes only exact matches; not-equal excludes one value and includes missing attributes.

Not !=
[name!="newsletter"]

Exclude one value

Exact =
[name="newsletter"]

Include one value

.not()
.not("[name='x']")

Faster alternative

Extension
!= jQuery only

Not native CSS

Examples Gallery

Example 1 follows the official jQuery API demo. Examples 2–5 cover missing-attribute behavior, comparison with equals, non-text inputs, and the recommended .not() pattern. Use the Try-it links to run each snippet.

📚 Official jQuery Demo

Append text to spans next to inputs whose name is not newsletter.

Example 1 — Official Demo: input[name!='newsletter']

Official jQuery demo — find inputs that do not have name="newsletter" and append bold text to the next sibling span.

jQuery
$( "input[name!='newsletter']" ).next().append( "<b>; not newsletter</b>" );

// Matches: no name, name="accept"
// Skips: name="newsletter"
Try It Yourself

How It Works

The input with no name attribute matches because it does not have name="newsletter". Only the exact excluded value is skipped.

Example 2 — Test Not-Equal Rules with .is()

Verify which inputs match [name!='newsletter'], including missing attributes.

jQuery
var cases = [
  { label: "newsletter", name: "newsletter" },
  { label: "accept", name: "accept" },
  { label: "no name", name: null }
];

cases.forEach( function( c ) {
  var $el = $( "<input type='radio'>" );
  if ( c.name ) { $el.attr( "name", c.name ); }
  $el.appendTo( "body" );
  console.log( c.label, "→", $el.is( "[name!='newsletter']" ) ? "MATCH" : "no" );
  $el.remove();
});
Try It Yourself

How It Works

Missing attributes match not-equal — a surprise for beginners who expect only “different values” to match. Plan for that when styling or validating form groups.

📈 Practical Patterns

Operator comparison, input types, and performance-friendly alternatives.

Example 3 — != vs = on the Same Input

See how equals and not-equal behave on one element.

jQuery
var $input = $( "<input>" ).attr( "name", "accept" ).appendTo( "body" );

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

$input.remove();
Try It Yourself

How It Works

For elements with the attribute set, != is the logical opposite of =. The difference appears when the attribute is missing entirely — only != matches those nodes.

Example 4 — Style Non-Text Inputs with input[type!='text']

Highlight every input whose type is not exactly text.

jQuery
$( "input[type!='text']" ).addClass( "special-input" );

// Matches: checkbox, submit, hidden, button
// Skips: type="text" only
Try It Yourself

How It Works

Excluding one common type is often simpler than listing every other type. Scope to a form container when the page has many inputs.

Example 5 — Faster Pattern: $("input").not("[name='newsletter']")

Official jQuery recommendation — use CSS plus .not() for better performance in modern browsers.

jQuery
// Same result as input[name!='newsletter'], often faster:
$( "input" ).not( "[name='newsletter']" ).addClass( "other-field" );

// jQuery runs querySelectorAll("input") natively, then filters
Try It Yourself

How It Works

Because [name!="value"] is not standard CSS, jQuery cannot delegate the whole query to native querySelectorAll. Splitting into a CSS selector plus .not() is the documented performance tip.

🚀 Common Use Cases

  • Exclude one fieldinput[name!='newsletter'] for non-newsletter radios.
  • Non-text inputsinput[type!='text'] to style special controls.
  • Skip hidden fieldsinput[type!='hidden'] before serializing a form.
  • Links not blanka[target!='_blank'] for same-tab navigation styling.
  • Options except defaultoption[value!=''] to ignore placeholder options.
  • Data roles[data-status!='archived'] to show active items only.

🧠 How jQuery Evaluates [attr!="value"]

1

Check attribute

Read whether the attribute exists on the candidate element.

DOM
2

Missing = match

If the attribute is absent, the element matches not-equal.

Include
3

Compare value

If present, match when the value is not exactly the excluded string.

Exclude
4

Return collection

Matching elements become a jQuery object for chaining.

📝 Notes

  • Available since jQuery 1.0 — jQuery extension, not standard CSS.
  • Equivalent in intent to :not([attr="value"]) per official docs.
  • Elements without the attribute also match — plan accordingly.
  • Comparison is case-sensitive, same as [attr="value"].
  • For performance, prefer $("css").not("[attr='value']") over [attr!="value"].
  • Scope broad queries: $("#form input[type!='hidden']").

Browser Support

The attribute not-equal selector is a jQuery extension in 1.0+. It works wherever jQuery runs, but it is not valid in native querySelectorAll. Official docs recommend .not("[attr='value']") on a CSS selector for better performance in modern browsers.

jQuery 1.0+ · Extension

jQuery [attribute!="value"]

Supported in all browsers that run your jQuery build. Not available outside jQuery — use .not() with standard CSS selectors when you need native query speed.

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
[attr!="value"] jQuery only

Bottom line: Not standard CSS. Prefer $("input").not("[name='newsletter']") for the same result with native selector optimization on the first pass.

Conclusion

The attribute not-equal selector [name!="value"] excludes elements with one exact attribute value — and also matches elements where the attribute is missing. jQuery’s official demo, $("input[name!='newsletter']").next().append("<b>; not newsletter</b>"), shows the pattern on radio inputs.

Remember it is a jQuery extension, not native CSS. When performance matters, use $("your-css-selector").not("[attr='value']") instead. Pair with form IDs or classes to keep queries readable on large pages.

💡 Best Practices

✅ Do

  • Use .not("[name='newsletter']") for better performance
  • Remember missing attributes also match !=
  • Scope: $("#form input[type!='hidden']")
  • Quote values with spaces or special characters
  • Pair with element type to narrow the search first

❌ Don’t

  • Assume != works in native querySelectorAll
  • Forget that elements without the attribute match too
  • Use bare $("[name!='x']") on huge DOM trees without scoping
  • Expect case-insensitive matching
  • Confuse != with “contains something else” substring logic

Key Takeaways

Knowledge Unlocked

Five things to remember about [attr!="value"]

Exclude one exact value — missing attributes count too.

5
Core concepts
02

Missing

Also matches

Rule
jQ 03

Extension

Not CSS

Note
.not 04

Faster

Use .not()

Perf
news 05

Official

name!=newsletter

Demo

❓ 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 attribute 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. That is an important difference from mentally inverting [attr="value"]. 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 and elements where name is any other value.
Did you know?

jQuery added several attribute operators beyond CSS — including [attr!="value"]. Standard CSS has =, ~=, |=, ^=, $=, and *=, but not !=. For exclusion in native CSS, use :not([attr="value"]) inside a valid selector list.

Continue to Attribute Starts With Selector

After excluding attribute values, learn prefix matching with [name^="value"].

Attribute starts-with 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.

6 people found this page helpful