jQuery | not() method with Examples
The not() is an inbuilt function in jQuery which is just opposite to the filter() method. This function will return all the element which is not matched with the selected element with the particular “id” or “class”.
Syntax:
$(selector).not(A)
The selector is the selected element which is not to be selected.
Parameters: It accepts a parameter “A” which is either “id” or “class” of the specified element.
Return Value: This will return all the elements except the selected elements.
Code #1:
In the below code all the paragraph element except with the class “main” get highlighted with the green color in the background.
<html> <head> jquery/3.3.1/jquery.min.js"></script> <script> $(document).ready(function() { $("p").not(".main").css("background-color", "green"); }); </script> </head> <body> <p class="main">Hello !!!</p> <p class="main">Welcome to</p> <p>GeeksforGeeks.!!!</p> </body> </html> |
Output:

Code #2:
In the below all the paragraph element with the id “main” get highlighted with the green color in the background.
<html> <head> jquery/3.3.1/jquery.min.js"></script> <script> $(document).ready(function() { $("p").filter("#main").css("background-color", "green"); }); </script> </head> <body> <p id="main">GeeksforGeeks.!!!</p> <p id="main">Hello !!!</p> <p>This is not() method of jQuery.!!!</p> </body> </html> |
Output:

Recommended Posts:
- jQuery | first() with Examples
- jQuery | one() with Examples
- jQuery | after() with Examples
- jQuery | eq() with Examples
- jQuery | val() with Examples
- jQuery | last() with Examples
- jQuery | on() with Examples
- jQuery | has() with Examples
- jQuery | unwrap() with Examples
- jQuery | undelegate() with Examples
- jQuery | prepend() with Examples
- jQuery | dblclick() with Examples
- jQuery | toggleClass() with Examples
- jQuery | wrap() with Examples
- jQuery | wrapAll() with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



