Difference between ID and Class Selector in jQuery Last Updated : 12 Jul, 2022 Comments Improve Suggest changes Like Article Like Report jQuery ID Selector: The #id selector specifies the id for an HTML element to be selected. It should not begin with a number and the id attribute must be unique within a document which means it can be used only one at a time. Syntax: $("#id")id is the element's specific id. Example: The following code demonstrates the jQuery ID selector. HTML <!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> <script> $(document).ready(function() { $("#paraID").css("background-color","red"); }); </script> </head> <body> <h1 style="color:green">GeeksforGeeks</h1> <p id="paraID"> jQuery #id selector is used for this p element. </p> </body> </html> Output: jQuery class Selector: The .class selector specifies the class for an element to be selected. It should not begin with a number. It gives styling to several HTML elements. Syntax: $(".class")class is the name of the class given for the HTML elements. Example: The following code demonstrates the jQuery class selector. HTML <!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> <script> $(document).ready(function() { $(".pClass").css("background-color", "blue"); }); </script> </head> <body> <h1 style="color:green">GeeksforGeeks</h1> <p class="pClass"> jQuery.class selector is used for p element </p> <span class="pClass"> jQuery.class selector is used for span element </span> </body> </html> Output: Differentiate the concepts of ID selector and class selector: The only difference between them is that "id" is unique in a page and it is applied to one HTML element while "class" selector can apply to multiple HTML elements. Comment More infoAdvertise with us Next Article Difference between ID and Class Selector in jQuery G geetanjali16 Follow Improve Article Tags : Web Technologies JQuery jQuery-Selectors jQuery-Questions Similar Reads Difference Between " . " and " # " Selector in CSS In CSS, selectors define which HTML elements receive specific styles.Class Selector (.): Targets elements with a specified class attribute, allowing multiple elements to share the same styling.ID Selector (#): Targets a single element with a unique ID attribute, ensuring that styles are applied to o 3 min read Difference between find() and closest() in jQuery Before looking at the differences between the find() and closest() methods, let us briefly understand what are these and what they do. 1. find() Method: This method is used to get all the filtered descendants of each element in the current set of matched elements. Syntax: $(selector).find('filter-ex 3 min read What's the difference between selector and filter() in jQuery? jQuery Selectors: allow us to select and manipulate HTML element(s). It is used to select HTML elements such as ids, classes, types, attributes, etc using jQuery selectors and then add any CSS properties or events to the selected HTML elements. Syntax: For selecting a button tag the syntax would be 2 min read Difference between $(this) and 'this' in jQuery In this article, we will learn the difference between this and $(this) in jQuery. this keyword: In JavaScript, this keyword is used to refer to the object it belongs to. The value that this stores is the current execution context of the JavaScript program.Thus, when used inside a function this value 3 min read Difference between text() and html() method in jQuery Text() Method: This method returns the text content of the selected elements. It overwrites the content of all the matches element while setting the content. Syntax: To return text content:$(selector).text()To set text content:$(selector).text(content)To set the text content using a function:$(selec 2 min read Like