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.
Remember
$(".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")
Put a dot before the class name, then optionally narrow by tag or parent.
Write $(".className") with the exact casing from your HTML.
Prefix with a tag when you only want certain elements: $("span.myClass").
Chain classes with no space for AND: $(".card.featured").
Scope under a parent when the page is large: $("#panel .item").
To change classes, use .addClass() / .removeClass() — the selector only finds.
Piece
Required?
Role
. + class name
Yes
Class to match (one of possibly many on the element)
Tag prefix
Optional
Limits matches to that element type
Extra .class
Optional
Requires additional classes on the same element
Return value
—
jQuery collection of matching elements
Pseudocode
Pseudocode
matches = []
for each element in document (or context):
classList = element.class attribute split by spaces
if targetClass is in classList:
matches.add(element)
return matches
// $(".a.b") → targetClass A AND targetClass B both in classList
// Native path: getElementsByClassName(targetClass) when possible
Reference
Cheat Sheet
Keep these facts handy while selecting by class.
Topic
Detail
Syntax
$(".className")
Since
jQuery 1.0 · CSS standard
Multi-class HTML
Only one listed class must match
AND classes
$(".a.b") — no space
Descendant
$(".a .b") — with space
Case
Case-sensitive in HTML
Native API
Uses getElementsByClassName when possible
Empty set
No match → length 0
Try it
Live Preview
Toggle which boxes have myClass, then run $(".myClass") and see what matches.
Sample elements
div.notMe / myClass
div.notMe
span.myClass
Same idea as the official jQuery demo — any tag with myClass can match.
Find.$(".active") returns a collection of matches.
Test..hasClass("active") returns a boolean for one element.
Change. To toggle the class, use .addClass() / .removeClass().
Rule. Selector = search; method = inspect or mutate.
Edge Cases & Pitfalls
Check these before relying on class selectors in real UIs.
space
.a.b vs .a .b
No space = both classes on one element. With a space = descendant. Mixing them up is the most common class-selector bug.
case
Class names are case-sensitive
$(".MyClass") will not match class="myclass" in HTML. Copy the exact spelling from your markup.
scope
Broad $(".item") hits the whole page
Reusable class names appear everywhere. Prefer $("#section .item") or a tag prefix when you mean a local set.
mutate
Selector does not add classes
$(".active") only finds. To change class lists, use .addClass(), .removeClass(), or .toggleClass().
Compatibility
Browser Support
The .class selector is standard CSS and has been in jQuery since 1.0. Class-only queries use native getElementsByClassName() when the browser provides it.
✓ Stable · CSS · jQuery 1.0+
jQuery .class
Supported across jQuery 1.x, 2.x, and 3.x in every browser that runs your jQuery build. Prefer current jQuery 3.x for modern projects.
100%Class selector support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
$(".class")Universal
Bottom line: Safe everywhere jQuery runs. Prefer scoped or tagged class queries on large pages for clarity and speed.
Analysis
Performance Notes
Approach
Cost
Best for
$(".class")
Cheap (native)
Simple class lookups
$("div.class")
Cheap
Tag-filtered matches
$("#id .class")
Cheapest scoped
Large pages / reusable class names
$(".a .b .c") deep
Higher
Only when deep nesting is required
Official docs note that class-only selectors can use getElementsByClassName(). Keep selectors simple and scoped when class names are reused across the page.
Remember
Key Takeaways
Role:$(".class") finds elements that include that class.
AND: use $(".a.b") — never a space — for both classes.
Scope: prefer $("#box .item") or $("div.item") on busy pages.
One line:$(".class") finds by class — chain without spaces for AND, scope when class names are reused.
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").