jQuery .is() Method

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Boolean test

What You’ll Learn

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

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.

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.

📝 Syntax

General forms of .is:

jQuery
.is( selector )
.is( function( index, element ) { return trueOrFalse; } )
.is( jQueryObject )
.is( domElement )

Parameters

  • selector (since 1.0) — a string containing a selector expression tested against each element in the current set.
  • function (since 1.6) — a callback returning true if the element matches; receives index and DOM element; this is the current element.
  • jQuery object (since 1.6) — returns true if any element in the current set appears in the provided collection.
  • DOM element (since 1.6) — returns true if any element in the current set is the same node as the argument.

Return value

  • true if at least one matched element satisfies the test; false otherwise (including when the set is empty).

Official jQuery API event-target example

jQuery
$( "ul" ).on( "click", function ( event ) {
  var target = $( event.target );
  if ( target.is( "li" ) ) {
    target.css( "background-color", "red" );
  }
});

⚡ Quick Reference

GoalCode
Is click target a list item?$(event.target).is("li")
Is parent a form?$("input").parent().is("form")
Custom per-element test$(el).is(function(){ return ...; })
Match against saved collection$(this).is(altItems)
Get matching elements (not boolean)$("li").filter(".active")
Multiple selector options$(this).is(".blue, .red")

📋 .is() vs .filter() vs .has()

Three methods that evaluate matches — boolean test, subset return, and descendant containment.

.is()
boolean

true/false — does not change collection

.filter()
jQuery

Returns matching subset to chain

.has()
parents

Containers with matching descendants

Use in
if (...)

.is() for conditionals and event guards

Examples Gallery

Examples 1–4 follow the official jQuery API documentation. Use DevTools or the Try-it links to run each snippet in the browser.

📚 Getting Started

Official jQuery demos for boolean matching in events and handlers.

Example 1 — Official Demo: Click Only When Target Is li

Attach a ul click handler that highlights only when the clicked node itself is a list item — not a child inside it.

jQuery
$( "ul" ).on( "click", function ( event ) {
  var target = $( event.target );
  if ( target.is( "li" ) ) {
    target.css( "background-color", "red" );
  }
});
Try It Yourself

How It Works

Events bubble from the deepest clicked node. event.target may be a strong or text node wrapper — .is("li") filters to direct list-item clicks only.

Example 2 — Official Demo: Callback Test for Two <strong> Tags

On li click, green if exactly two strong elements inside; red otherwise — official function form.

jQuery
$( "li" ).on( "click", function () {
  var li = $( this ),
    isWithTwo = li.is( function () {
      return $( "strong", this ).length === 2;
    });
  if ( isWithTwo ) {
    li.css( "background-color", "green" );
  } else {
    li.css( "background-color", "red" );
  }
});
Try It Yourself

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();
});
Try It Yourself

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.

jQuery
var inForm = $( "#in-form input" ).parent().is( "form" );
var inPara = $( "#in-para input" ).parent().is( "form" );

// inForm → true | inPara → false
Try It Yourself

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" );
  }
});
Try It Yourself

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.

🚀 Common Use Cases

  • Event target guardsif ($(e.target).is("button")) { ... }.
  • Form field context$("input").parent().is("form").
  • Toggle visibility logicif ($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.

📝 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.

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 Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All 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.

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.

💡 Best Practices

✅ Do

  • Use .is() inside if statements and event guards
  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about .is()

Test without changing the set.

5
Core concepts
🖼 02

.filter()

Subset

Compare
🎯 03

Events

target

Pattern
fn 04

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.

Back to jQuery Traversing

Explore more DOM traversal methods as the collection grows.

Traversing hub →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful