
- jQuery - Home
- jQuery - Roadmap
- jQuery - Overview
- jQuery - Basics
- jQuery - Syntax
- jQuery - Selectors
- jQuery - Events
- jQuery - Attributes
- jQuery - AJAX
- jQuery CSS Manipulation
- jQuery - CSS Classes
- jQuery - Dimensions
- jQuery - CSS Properties
- jQuery Traversing
- jQuery - Traversing
- jQuery - Traversing Ancestors
- jQuery - Traversing Descendants
- jQuery References
- jQuery - Selectors
- jQuery - Events
- jQuery - Effects
- jQuery - HTML/CSS
- jQuery - Traversing
- jQuery - Miscellaneous
- jQuery - Properties
- jQuery - Utilities
- jQuery Plugins
- jQuery - Plugins
- jQuery - PagePiling.js
- jQuery - Flickerplate.js
- jQuery - Multiscroll.js
- jQuery - Slidebar.js
- jQuery - Rowgrid.js
- jQuery - Alertify.js
- jQuery - Progressbar.js
- jQuery - Slideshow.js
- jQuery - Drawsvg.js
- jQuery - Tagsort.js
- jQuery - LogosDistort.js
- jQuery - Filer.js
- jQuery - Whatsnearby.js
- jQuery - Checkout.js
- jQuery - Blockrain.js
- jQuery - Producttour.js
- jQuery - Megadropdown.js
- jQuery - Weather.js
jQuery :not() Selector
The :not() Selector in jQuery is used to select all elements that do not match a given selector. This selector can be used with any jQuery selector to select everything except the specified element in a group.
Syntax
Following is the syntax of jQuery :not() Selector −
$(":not(selector)")
Parameters
Here is the description of the above syntax −
- The :not(selector) specifies the element to not select.
Example 1
In the following example, we are using the jQuery :not() Selector to select all the <p> elements that do not have the class "exclude" −
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p:not(.exclude)").css("background-color", "yellow"); }); </script> </head> <body> <p>This paragraph will be blue.</p> <p class="exclude">This paragraph will not be blue.</p> <p>This paragraph will be blue too.</p> </body> </html>
After executing the above program, the selected elements will be highlighted with yellow background color.
Example 2
In this example, we are selecting all the <div> elements that do not have the ID "exclude" −
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(document).ready(function(){ // Select all <div> elements that do not have the ID 'exclude' and set their background color to yellow $("div:not(#exclude)").css("background-color", "yellow"); }); </script> </head> <body> <div>This div will have a yellow background.</div> <div id="exclude">This div will not have a yellow background.</div> <div>This div will have a yellow background too.</div> </body> </html>
The <div> elements that do not have the ID "exclude" will be highlighted with yellow background color.
jquery_ref_selectors.htm
Advertisements