The class selector$(".class") (since jQuery 1.0) selects every element whose class attribute includes that name. An element can have many classes — only one must match. It is a standard CSS selector; jQuery uses native getElementsByClassName() when available.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
$(".myClass") // any tag with class myClass
$("div.myClass") // only divs with that class
$(".myclass.otherclass") // both classes required (no space!)
$(".a .b") // .b inside .a (descendant)
// Change classes with .addClass() / .removeClass()
// Test with .hasClass("myClass")
Call
What it does
Class
Learn the jQuery class selector .class: match elements by CSS class, require multiple classes with .a.b, scope queries, official myClass demo, pitfalls, browser support, and FAQs.
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Write $(".className") with the exact casing from your HTML.
Step 2
Prefix with a tag when you only want certain elements: $("span.myClass").
Step 3
Chain classes with no space for AND: $(".card.featured").
Return Value
Return Value
Description
jQuery object
Most setters and traversing helpers return the jQuery collection so you can chain more methods.
jQuery Examples
Example 1 — Official $(".myClass")
Find every element that includes the class myClass.
Why. Tag prefixes make intent clearer and reduce accidental matches.
Frequently Asked Questions
The class selector .class matches every element whose class attribute includes that class name. $(".myClass") finds any tag with class="myClass", or class="foo myClass bar" where myClass is one of several classes.
Chain class names with no space: $(".myclass.otherclass") matches only elements that have both classes. A space means descendant — $(".a .b") selects .b inside .a, not an element with both classes.
In HTML documents, class names are case-sensitive. $(".MyClass") does not match class="myclass". Match the exact spelling and casing used in your HTML.
Yes. For class-only selectors, jQuery uses the browser’s native getElementsByClassName() when supported — fast and well optimized. More complex selectors still go through Sizzle.
$(".active") selects elements that already have the class. .addClass("active") adds the class to elements in an existing jQuery collection. Select to find; .addClass() to change.
Yes. Official jQuery docs: an element can have multiple classes; only one of them must match. class="card featured myClass" still matches $(".myClass").