How to Select All Elements without a Given Class using jQuery? Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report In jQuery, selecting elements that do not have a specific class can be useful when you want to manipulate or style all elements except those matching a certain condition. This approach allows for more precise control over the elements in various dynamic situations.Here we have some common approaches to selecting all elements without a given class using jQuery:Table of ContentUsing :not(selector) Pseudo-ClassUsing .not(selector) Method1. Using :not(selector) Pseudo-ClassThe :not(selector) pseudo-class in jQuery filters out elements that match a specific selector, such as a class, ID, or attribute. This method lets you apply actions only to elements that do not meet the given criteria.Example 1: Highlight List Items Without the Class activeIn this example, we use the :not() selector to target list items that do not have the class active and apply a yellow background. html <!DOCTYPE html> <html> <head> <title> How to select all elements without a given class using jQuery ? </title> <meta charset="utf-8"> <script src="https://code.jquery.com/jquery-1.10.2.js"> </script> </head> <body> <h1 style="color:green">GeeksforGeeks</h1> <b> Select all elements without a<br> given class using jQuery </b> <ul> <li class="active">element 1</li> <li>element 2</li> <li>element 3</li> <li>element 4</li> </ul> <script> $("li:not(.active)").css( "background-color", "yellow"); </script> </body> </html> Output:2. Using .not(selector) MethodThe .not(selector) method in jQuery excludes elements matching the specified selector from a set of selected elements. It allows you to dynamically filter out elements by class, ID, or other attributes, ensuring actions only affect the remaining elements.Example 2: Change Border Color for <div> Elements Without a Specific Class or IDThis example demonstrates how to select all <div> elements that do not have the class green or the ID blue, and change their border color to red. HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://code.jquery.com/jquery-1.10.2.js"> </script> <style> div { width: 50px; height: 50px; margin: 10px; float: left; border: 2px solid black; } .green { background: #8f8; } .orange { background: orange; } #blue { background: #99f; } </style> </head> <body> <h1 style="color:green">GeeksforGeeks</h1> <b> Select all elements without a given class using jQuery </b> <br><br> <div></div> <div id="blue"></div> <div></div> <div class="green"></div> <div class="green"></div> <div class="orange"></div> <div></div> <script> $("div").not(".green, #blue") .css("border-color", "red"); </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to select a div with a certain class using jQuery ? T tanishqporwar22 Follow Improve Article Tags : JQuery Technical Scripter 2019 jQuery-Misc Similar Reads How to select a div with a certain class using jQuery ? Given a HTML document containing many div element with classes. Here the task is to select a div with a certain class, that doesn't have another class. There are two approaches to solve this problem. In one of them, we will use a method and in the other one, we will use not selector. Approach 1: Fir 3 min read How to select elements with no visible children using jQuery ? In this article we are going to learn how to select elements whose property is not visible or hidden. It simply means that the display property of that particular element is hidden, and we need to show whatever present in that element using the Jquery.We can easily do this by using the Jquery:hidden 2 min read How to find all children with a specified class using jQuery ? There are lots of javascript libraries like - anime.js, screenfull.js, moment.js, etc. JQuery is also a part of javascript libraries. It is used to simplify the code. It is a lightweight and feature-rich library. In this article, we will learn how to find all children with a specified class of each 2 min read How to find element with specific ID using jQuery ? The question is to determine whether an element with a specific id exists or not using JQuery. jQuery on() Method: This method adds one or more event handlers for the selected elements and child elements.Syntax: $(selector).on(event, childSelector, data, function, map)Parameters: event: It is requir 3 min read How to select all sibling elements of an element using jQuery ? In this article, we will discuss how to select all sibling elements of an element using jQuery. To select all sibling elements of an element, we will use the siblings() method. The siblings() method is used to find all sibling elements of the selected element. The siblings are those having the same 2 min read How to find an element by text using jQuery ? We will learn how to find an element using jQuery's API. This article requires some knowledge of HTML, CSS, JavaScript, Bootstrap, and jQuery. The elements can be selected based on whether they contain the string we want to find. This can be done using the jQuery contains selector to select elements 2 min read Like