How to select a div with a certain class using jQuery ? Last Updated : 27 Oct, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report 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: First, select the DIV with certain class using jQuery Selector and then use :not selector to ignore the elements of specific class. Example: This example implements the above approach. html <!DOCTYPE HTML> <html> <head> <title> Select a div with a certain class, that doesn't have another class. </title> <style> body { text-align: center; } h1 { color: green; } .div { background: green; height: 50px; width: 200px; margin: 0 auto; color: white; border: 2px solid black; } </style> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"> </script> </head> <body> <h1> GeeksforGeeks </h1> <p> Click on button to select a div with a certain class, that doesn't have another class. </p> <!-- div elements --> <div class="first div"> This is first Div </div> <br> <div class="second div"> This is second Div </div> <br> <div class="third div"> This is third Div </div> <br> <button onClick="GFG_Fun()"> click here </button> <br> <p id="geeks"> </p> <script> /* main function */ function GFG_Fun() { /* using the :not selector */ $('.div:not(.first)') .css("background-color", "#173F5F"); $('#geeks') .text("DIV Box of class 'first' is not selected."); } </script> </body> </html> Output: Approach 2: First, select the DIV with certain class using jQuery Selector and then Use .not() method to ignore the elements of specific class. Example: This example implements the above approach. html <!DOCTYPE HTML> <html> <head> <title> Select a div with a certain class, that doesn't have another class. </title> <style> body { text-align: center; } h1 { color: green; } .div { background: green; height: 50px; width: 200px; margin: 0 auto; color: white; border: 2px solid black; } </style> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"> </script> </head> <body> <h1> GeeksforGeeks </h1> <p> Click on button to select a div with a certain class, that doesn't have another class. </p> <!-- div elements --> <div class="first div"> This is first Div </div> <br> <div class="second div"> This is second Div </div> <br> <div class="third div"> This is third Div </div> <br> <button onClick="GFG_Fun()"> click here </button> <br> <p id="geeks"> </p> <script> /* main function */ function GFG_Fun() { /* using the .not() method */ $('.div').not('.first') .css("background-color", "#173F5F"); $('#GFG_DOWN') .text("DIV Box of class 'first' is not selected."); } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to find all children with a specified class using jQuery ? P PranchalKatiyar Follow Improve Article Tags : JQuery jQuery-Misc Similar Reads 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 Select All Elements without a Given Class using jQuery? 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 2 min read How to detect and change the content/style of a div using jQuery ? The changes to the html/text of a div can be detected using jQuery on() method. The on() is used to attach one or more event handlers for the selected elements and child elements in the DOM tree. The on() method is the replacement of the bind(), live() and delegate() method from the jQuery version 1 2 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 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 add a class on click of anchor tag using jQuery ? In this article, we will see how to add a class on click of an anchor tag using jQuery. To add a class on click of the anchor tag, we use the addClass() method. The addClass() method is used to add more properties to each selected element. It can also be used to change the property of the selected e 2 min read Like