The .is() traversing method tests the current jQuery collection and returns true or false — it does not create a new jQuery object. This tutorial covers the official event-target list demo, callback tests for content, div click selector checks, form parent validation, and compares .is() with .filter().
01
Boolean
true / false
02
Selector
.is("li")
03
Function
Callback test
04
jQ / DOM
Since 1.6
05
vs .filter()
Test vs subset
06
Since 1.0
Core API
Fundamentals
Introduction
Most jQuery traversing methods return a new jQuery object — .filter(), .find(), .first(). Sometimes you only need a yes-or-no answer: Is this element a list item? Is its parent a form? Does it match this saved collection? The .is() method answers those questions with a boolean.
Available since jQuery 1.0 for selectors (callback, jQuery object, and DOM element forms since 1.6), .is() checks the current matched set without modifying it. It returns true if at least one element matches; otherwise false. This makes it ideal inside if statements and event handlers.
Concept
Understanding the .is() Method
Given a jQuery object representing a set of DOM elements, .is(selectorOrFunctionOrElement) tests whether any element in that set matches. The return type is a plain JavaScript boolean — not a jQuery wrapper.
In event handlers, $(event.target).is("li") checks whether the actual clicked node is an li, ignoring bubbled clicks from nested span or strong children. That pattern prevents accidental triggers when users click text inside a list item.
💡
Beginner Tip
.filter(".active") gives you active elements to style. .is(".active") tells you whether the current set includes any active element — use it in if branches, not for chaining more jQuery methods.
Item with two strong → green on click
Item with one strong → red on click
How It Works
The callback runs per element in the set (here, one li). .is(function...) returns true if any callback invocation returns true — same content logic as .filter() but yields a boolean.
📈 Practical Patterns
Multi-selector div checks, form parent validation, and jQuery collection matching.
Example 3 — Official Demo: Div Click with Multiple Selector Tests
One-click div handler branches on :first-child, class list, and :contains — official Example 1 pattern.
jQuery
$( "div" ).one( "click", function () {
if ( $( this ).is( ":first-child" ) ) {
$( "p" ).text( "It's the first div." );
} else if ( $( this ).is( ".blue,.red" ) ) {
$( "p" ).text( "It's a blue or red div." );
} else if ( $( this ).is( ":contains('Peter')" ) ) {
$( "p" ).text( "It's Peter!" );
} else {
$( "p" ).text( "It's nothing special." );
}
$( "p" ).show();
});
First div → "It's the first div."
Blue/red div → "It's a blue or red div."
Peter div → "It's Peter!"
How It Works
Comma-separated selectors in .is(".blue,.red") match if any alternative applies. Pseudo-selectors like :contains work inside .is() the same as in query strings.
Example 4 — Official Demo: Is the Parent a form?
Compare checkbox inside form vs inside paragraph — official Examples 2 and 3.
Checkbox in form → isFormParent = true
Checkbox in p → isFormParent = false
How It Works
.parent() returns the immediate parent as a jQuery object. .is("form") asks whether that parent node is a form element — a common validation and serialization guard.
Example 5 — Official Demo: Match Against a jQuery Collection
Blue alternating browser list items slide up on click; others turn red — official Example 4.
jQuery
var alt = $( "#browsers li:nth-child(2n)" ).css( "background", "#0ff" );
$( "li" ).on( "click", function () {
var li = $( this );
if ( li.is( alt ) ) {
li.slideUp();
} else {
li.css( "background", "red" );
}
});
Cyan alternating items (Safari, Opera) → slideUp
Other items → red background
How It Works
li.is(alt) checks whether the clicked item exists in the pre-built alternating collection. Official Example 5 reverses the call — alt.is(this) — with the same boolean result.
Applications
🚀 Common Use Cases
Event target guards — if ($(e.target).is("button")) { ... }.
Form field context — $("input").parent().is("form").
Toggle visibility logic — if ($panel.is(":visible")) { ... }.
Custom element rules — callback to test attributes, child count, or state.
Compare to cached set — $(this).is(selectedItems).
Early return in handlers — skip processing when !$(el).is(".enabled").
🧠 How .is() Returns true or false
1
Start with collection
jQuery object holds elements to test.
Input
2
Run test per element
Selector, callback, jQuery set, or DOM node.
Test
3
Any match?
Stop at first true — or false if none.
Evaluate
4
✅
Return boolean
Plain true/false — original set unchanged.
Important
📝 Notes
Available since jQuery 1.0 (selector); function, jQuery object, and DOM forms since 1.6.
Returns a boolean — not chainable for further jQuery methods on the result.
Does not modify the jQuery object — unlike .filter(), .has(), and .find().
True if at least one element in the set matches — not all elements required.
Empty collection always yields false.
Ideal inside event handlers, conditionals, and validation checks.
Compatibility
Browser Support
.is() has been part of jQuery since 1.0+ (extended forms since 1.6). It relies on selector matching and callback iteration with no browser-specific behavior.
✓ jQuery 1.0+
jQuery .is()
Supported in jQuery 1.x, 2.x, and 3.x across all modern browsers and IE with supported jQuery builds. Returns a native boolean usable in any JavaScript conditional.
100%With jQuery loaded
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
.is()Universal
Bottom line: Safe in any jQuery project. Use .is() to test; use .filter() when you need matching elements back.
Wrap Up
Conclusion
The jQuery .is() method tests whether elements in the current collection match a selector, callback, jQuery object, or DOM node — and returns true or false. It is the go-to tool when you need an answer, not a new jQuery object.
Remember the official event lesson: clicking text inside a list item makes event.target a child node — use .is("li") to act only on direct list-item clicks. Pair .is() with conditionals; use .filter() when you need the matching elements for styling or manipulation.
Test $(event.target) before acting on bubbled clicks
Use callback form for rules selectors cannot express
Cache jQuery collections and test with .is(cachedSet)
Remember empty sets return false — safe for guards
❌ Don’t
Chain jQuery methods on .is() — it returns boolean
Use .is() when you need matching elements — use .filter()
Assume all elements must match — only one true result is enough
Confuse .is() with .has() — self vs descendants
Replace readable .filter().length checks when .is() is clearer
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about .is()
Test without changing the set.
5
Core concepts
T/F01
.is()
Boolean
API
🖼02
.filter()
Subset
Compare
🎯03
Events
target
Pattern
fn04
Callback
Custom
Form
1+05
Any match
true
Rule
❓ Frequently Asked Questions
.is() checks whether at least one element in the current jQuery collection matches a selector, passes a callback test, or matches a jQuery object or DOM element. It returns true or false — it does not return a new jQuery object.
.filter() returns a new jQuery object containing matching elements. .is() returns a boolean — true if any element in the set matches, false otherwise. Use .filter() to keep matches; use .is() to test without changing the collection.
No. Unlike .filter(), .has(), and .find(), .is() only tests the current set and returns true/false. The original jQuery object is unchanged — ideal inside event handlers and conditionals.
If at least one element in the current matched set satisfies the selector, callback, jQuery collection, or DOM element argument. For an empty jQuery object, .is() returns false.
Yes, since jQuery 1.6. .is(function(index, element) { ... }) runs the function for each element. If any call returns true, .is() returns true. Inside the callback, this refers to the current DOM element.
When events bubble from child elements, $(event.target).is('li') checks whether the clicked node itself is a list item — not a span or strong inside it. This prevents child clicks from triggering parent-only logic.
Did you know?
Before jQuery 1.6 added the callback and collection forms, developers often wrote $("li").filter(".active").length > 0 to test for matches. $("li").is(".active") expresses the same intent in one readable call and short-circuits on the first match.