Attribute Not Equal [attr!="value"] JQ Home  <<  Selectors  <<  Attribute Not Equal [attr!="value"]

Attribute Value Non-Match selector.

Shorthand version $('[attr!="value"]')

Description

The [attr!="value"] selector, selects all elements that either don't have the specified attribute name, or do have the specified attribute but not with a value matching the specified string.

  • Being a jQuery extension the [attr!="value"] pseudo selector is not part of any current CSS specification. Therefore [attr!="value"] cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method.
  • The same results can be achieved with valid CSS using $("CSSselector").not('[name="value"]'), without the hit to performance.
  • If this selector is not preceded by another selector, the universal selector ("*") is implied and so the whole DOM will be searched. Use another selector as in the examples below to narrow the search and improve performance.

Syntax

Signature Description
jQuery('[attr!="value"]')Attribute Value Non-Match

Parameters

Parameter Description
attrThe attribute name.
valueThe attribute value which can be either an unquoted single word or a quoted string.

Return

N/A.

Attribute Not Equal [attr!="value"] Examples Selectors  <<  Top

Selects all elements that either don't have the specified attribute name, or do have the specified attribute but not with a value matching the specified string.

The following example will select all 'h3' elements that don't have the id attribute with a value of 'notequal' and turn the background colour orange.



$(function(){
  $('#btn1').on('click', function() {
    $('h3[id!="notequal"]').css('backgroundColor', 'orange');
  });
}); 

Press the buttons below to action the above code:

A 'h3' heading 3 with no id attribute

The following example will select 'input' elements within the 'form' element below that have a type attribute that doesn't equal 'text' or a 'type' attribute that doesn't equal 'image' and change their borders colors to orange and yellow respectively.

When we press the left button any input elements that have a type attribute that doesn't equal 'text' will have 3px orange borders.

When we press the right button any input elements that have a type attribute that doesn't equal 'image' will have 3px yellow borders.


$(function(){
  $('#btn2').on('click', function() {
    $('.formfields2 input[type!="text"]').css('border', '3px solid orange');
  });
  $('#btn3').on('click', function() {
    $('.formfields2 input[type!="image"]').css('border', '3px solid yellow');
  });
}); 
Pie Survey     

Userame:      

Password:               

     

Which pie do you prefer?:

Select a pie shape: 

            

Press the button below to action the above code:

            

Related Tutorials

jQuery Basic Tutorials - Lesson 4 - jQuery Selectors

jQuery Basics

jQuery Basics

jQuery Intermediate

jQuery Intermediate

jQuery Advanced

jQuery Advanced

jQuery Reference

API by Function Types

API Alphabetically

jQuery Glossary

Function Type

Ajax

Attributes & Properties

Core & Internals

DOM Element Methods

Effects

Events

Filtering

Manipulation

Objects

Selectors

Attribute

Attribute Contains Prefix Selector

Attribute Contains Selector

Attribute Contains Word Selector

Attribute Ends With Selector

Attribute Equals Selector

Attribute Not Equal Selector

Attribute Starts With Selector

Has Attribute Selector

Multiple Attribute Selector

Basic

All Selector ('*')

Class Selector ('.class')

Element Selector

ID Selector ('#id')

Multiple Selector

Basic Filter

:animated Selector

:eq() Selector

:even Selector

:first Selector

:gt() Selector

:header Selector

:lang Selector

:last Selector

:lt() Selector

:not() Selector

:odd Selector

:root Selector

:target Selector

Child Filter

:first-child Selector

:first-of-type Selector

:last-child Selector

:last-of-type Selector

:nth-child() Selector

:nth-last-child() Selector

:nth-last-of-type() Selector

:nth-of-type() Selector

:only-child Selector

:only-of-type Selector

Content Filter

:contains() Selector

:empty Selector

:has Selector

:parent Selector

Form

:button Selector

:checkbox Selector

:checked Selector

:disabled Selector

:enabled Selector

:file Selector

:focus Selector

:image Selector

:input Selector

:password Selector

:radio Selector

:reset Selector

:selected Selector

:submit Selector

:text Selector

Hierarchy

Child Selector

Descendant Selector

Next Adjacent Selector

Next Siblings Selector

Visibility Filter

:hidden Selector

:visible Selector

Traversal

Utilities